I am working on a function which getting users my problem is i have to return the result of the two queries as one result in the rows.next() and rows1.next() like user_id,subject,phone and also body as same result .
here is what i made but it doesn't work cloud you please help me out with some suggestions , thanks indeed func GetUsers() (users []Users, err error) {
users = make([]Users, 0)
rows, err := db1.Query("SELECT user_id, subject,phone FROM users limit 11")
rows1, err := db1.Query("Select body from users limit 11")
defer rows.Close()
if err != nil {
// handle this error better than this
log.Fatal(err)
//return
}
var user Users
for rows.Next() {
rows.Scan(&user.ID, &user.Subject, &user.Phone)
users = append(users, user)
}
for rows1.Next() {
rows1.Scan(&user.Body)
users = append(users, user)
}
return
}
i have a table called users which has no primary key , basically user_id . name. body 1 . model . 2 1 . brand. 1 1 . fuel. 3 1 . date .1 1 . year . 1
i have to have a result userid , model, brand , fuel ,date,year 1 . 2 1 . 3 . 1 . 1
so the values in the column name gonna be as a rows i have already defined my struct which containning all the fields needed