Sobes.tech
Junior — Middle

What types of SQL queries can you create and use in practice?

sobes.tech AI

Answer from AI

In practice with SQL queries, the following types are usually used:

  • SELECT — for retrieving data from tables.
  • INSERT — for adding new records.
  • UPDATE — for modifying existing data.
  • DELETE — for deleting records.
  • JOIN — for combining data from multiple tables.
  • CREATE TABLE — for creating new tables.
  • ALTER TABLE — for modifying the structure of tables.

Example of a simple SELECT query in Go using database/sql:

rows, err := db.Query("SELECT id, name FROM users WHERE active = ?", true)
if err != nil {
    log.Fatal(err)
}
for rows.Next() {
    var id int
    var name string
    err = rows.Scan(&id, &name)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(id, name)
}