> For the complete documentation index, see [llms.txt](https://twharmon.gitbook.io/gosql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://twharmon.gitbook.io/gosql/basic-usage/select-queries.md).

# Select Queries

Selecting single rows or multiple rows is easy.

This type is used in the examples on this page.

```go
type User struct {
    ID       int `gosql:"primary"`
    Email    string
    IsActive bool
}
```

{% hint style="info" %}
When building queries with GoSQL, remember to use the table column names (snake case).
{% endhint %}

## Single Row

To select a single row, pass a reference to a struct to`Get()` :

```go
var user User
db.Select("*").Get(&user)
```

{% hint style="warning" %}
`Get()` returns an `error` that should be checked. This guide does not check for errors.
{% endhint %}

Selecting some fields only:

```go
var user User
db.Select("id", "is_active").Get(&user)
```

Select with a where clause:

```go
var user User
db.Select("id", "is_active").
    Where("is_active = ?", true).
    Get(&user)
```

## Multiple Rows

To select multiple rows, it is best to pass a reference to a slice of structs to`Get()` :

```go
var users []User
db.Select("*").Limit(100).Get(&users)
```

{% hint style="warning" %}
When selecting multiple rows, you must set the limit with `Limit()`. If you don't, an error will be returned.
{% endhint %}

Sorting results:

```go
var users []User
db.Select("*").
    Limit(100).
    OrderBy("email ASC").
    Get(&users)
```

Use offset to get paginated results. This would be page 2 with a page size of 10:

```go
var users []User
db.Select("*").
    Limit(10).
    Offset(10).
    Get(&users)
```
