squirrel
squirrel copied to clipboard
Multiple value where clause using squirrel
I'm trying to recreate this query with squirrel:
SELECT c.userID, c.name, o.orderID FROM users as c join order as o
ON c.userID = o.userID where orderID IN ('a', 'b');
The closest I can come up with is this and it's wrong:
query := sq.Select("c.id, c.name, o.orderID").
From("users").join("order as o using (userID)")
Where(sq.Eq{
"id": []string{'a', 'b'},
})
One option is there to have multiple Where(sq.Eq{}
but if i have 100 orderIDs it will grow alot and i think it will be ugly
you can use squirrel.And
You can use this code
sq.StatementBuilder.PlaceholderFormat(sq.Colon).Select("c.userID, c.name, o.orderID").From("users AS c").
Join("orders AS o ON c.orderID = o.orderID").
Where(sq.Eq{"orderID": []string{"a", "b"}})