donqh00404
donqh00404
2013-09-25 18:41

Golang使用JOIN查询多个数据库

  • mysql
  • sql

Using the golang example below, how can I query (JOIN) multiple databases. For example, I want to have the relation db1.username.id = db2.comments.username_id.

id := 123
var username string

err := db.QueryRow("SELECT username FROM users WHERE id=?", id).Scan(&username)

switch {
    case err == sql.ErrNoRows:
       log.Printf("No user with that ID.")

    case err != nil:
       log.Fatal(err)

    default:
        fmt.Printf("Username is %s
", username)
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答