> For the complete documentation index, see [llms.txt](https://query.docs.doyto.win/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://query.docs.doyto.win/object-concepts/query-object/logic-suffix-field.md).

# Logic-Suffix Field

By default, the query conditions corresponding to each field in a query object are connected with the **AND** operator.\
If you want to define query conditions connected with the **OR** operator, you need to define the suffix **`Or`** in the field name, and the following three field types are supported:

```java
public class UserQuery extends PageQuery {
    // ...
    private List<String> nameStartOr;
    private UserQuery userOr;
    private List<UserQuery> usersOr;
}
```

### List\<String> nameStartOr;

```java
UserQuery userQuery = UserQuery.builder().nameStartOr(List.of("Bob","John","Tim")).build();
List<UserEntity> users = userDataAccess.query(userQuery);
// SQL="SELECT id, name, score, memo, deleted FROM t_user 
// WHERE (name LIKE ? OR name LIKE ? OR name LIKE ?)" args="[Bob% John% Tim%]"
```

### UserQuery userOr;

```java
UserQuery userQuery = UserQuery.builder().nameStartOr(Arrays.asList(1, 4, 12)).deleted(trur).build();
List<UserEntity> users = userDataAccess.query(userQuery);
// SQL="SELECT id, name, score, memo, deleted FROM t_user 
// WHERE (id IN (?, ?, ?) OR deleted = ?)" args="[1 4 12 true]"
```

### List\<UserQuery> usersOr;

```java
UserQuery userQuery = UserQuery.builder()
    .usersOr(List.of(
        UserQuery.builder().idIn(List.of(1L, 4L, 12L)).deleted(true).build(),
        UserQuery.builder().idGt(10L).deleted(false).build()
    )).build();
List<UserEntity> users = userDataAccess.query(userQuery);
// SQL="SELECT id, name, score, memo, deleted FROM t_user
// WHERE (id IN (?, ?, ?) AND deleted = ? OR id > ? AND deleted = ?)"
// args="[1 4 12 true 10 false]"
```

## And Suffix

When a field name ends with **`And`**, the logical operator connecting multiple query conditions is **AND**.

```java
public class UserQuery extends PageQuery {
    // ...
    private UserQuery userOr;
    private UserQuery userAnd;
}
```

### UserAnd \*UserQuery

```java
UserQuery userAnd = UserQuery.builder().idIn(List.of(1L, 4L, 12L)).deleted(false).build();
UserQuery userOr = UserQuery.builder().deleted(true).userAnd(userAnd).build();
UserQuery userQuery = UserQuery.builder().scoreLt(80).userOr(userOr).build();
List<UserEntity> users = userDataAccess.query(userQuery);
// SQL="SELECT id, name, score, memo, deleted FROM t_user
// WHERE score < ? AND (deleted = ? OR id IN (?, ?, ?) AND deleted = ?)"
// args="[80 true 1 4 12 false]"
```

### Related Article

[How to express `select * from user where id = ? or name = ? and age = ?` in GoooQo](https://blog.doyto.win/post/goooqo-or-clause-en/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://query.docs.doyto.win/object-concepts/query-object/logic-suffix-field.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
