Is there a better way of dealing with a MYSQL SELECT query on a id that can also be nil. The code below works, but I would like to have it in one query. Is that possible?
if parent_id != nil {
err := db.QueryRow("SELECT id FROM category WHERE parent_id = ?", parent_id).Scan(&category_id)
if err != nil {
fmt.Println("ID not found", err)
}
} else {
err := db.QueryRow("SELECT id FROM category WHERE parent_id is NULL").Scan(&category_id)
if err != nil {
fmt.Println("ID not found", err)
}
}