I am running the below query, but only get the first id value:-
select * from `table` where table`.`id` in ('1', '2', '3', '4', '5', '6', '7', '9', '11', '13', '14', '15', '17') and `table`.`deleted_at` is null
I have done the following:-
var aID = make([]string, 0)
var in India // india is struct
for rows.Next() {
cook := rows.Scan(&in.ID)
aID = append(aID, strconv.Itoa(in.ID))
}
asID = strings.Join(aID, ",")
anotherRow,err := db.Query("SELECT * from table2 where id in (?)", asID)
if err != nil { fmt.Printf("Error: ", err) }
// ... Other line follows up with "for anotherRow.Next() and fetching"
While fetching data, it only returns value of "1" and ignores all other ID passed to it, which are '2', '3', '4', '5', '6', '7', '9', '11', '13', '14', '15', '17'.
How can I pass it correctly?
I am using go-sql-driver/mysql.
FAQ :
aIDdoes contain all those numbers as string andtable has all the rows available with provided above
id.tableis from whereidis fetched and appended toaIDand another record withidstored inaIDare fetched withinstatement fromtable2.
Thanks
sqlx.Into solve this. Take a look at stackoverflow.com/questions/40565805/…'1','2','3',...but in1,2,3,....WHERE id IN ('1,2,3,4...')and mysql matches only the first value in that string, so id equal to1or'1'will match but id equal to2or'2'will not