I have this query that works fine on mysql and return the intended result, but sqlx has difficulty to handle it:
var jokes []model.Joke
err := shared.Dbmap.Select(&jokes, "SELECT * FROM joke INNER JOIN jokevote ON joke.id=jokevote.joke_id AND jokevote.vote=? AND joke.user_id=?", 1, userId)
if err != nil {
log.Println(err)
}
At runtime, I get no result but this error message in terminal:
missing destination name joke_id
I don't have this issue when querying a single table.
So I'm wondering what is wrong here and how to fix it?
UPDATE: Here are the structs:
type Joke struct {
ID int `db:"id" json:"id"`
UserID int `db:"user_id" json:"user_id"`
Title string `db:"title" json:"title"`
Content string `db:"content" json:"content"`
...
}
type JokeVote struct {
ID int `db:"id" json:"id"`
JokeID int `db:"joke_id" json:"joke_id"`
UserID int `db:"user_id" json:"user_id"`
Vote int `db:"vote" json:"vote"`
}