If i remove USING (nid,sid), i get the column is ambigious error. I don’t quite understand what USING does here? Is it joining the nid and sid returned from the subquery to the nid, sid in the outer select query?
SELECT sid, nid, max_rating FROM outcomes
JOIN (SELECT nid, sid, MAX(rating) AS max_rating from outcomes group by nid, sid) AS newtable
USING (nid, sid)
WHERE rating = max_rating AND name LIKE '%test%'
Yes,
USINGis being used to join the two tables using bothnidandsid. But it has added advantages.nidandsid, as theUSINGstatement merges the columns together.nidorsidin yourWHEREclause, you would not need to specify which table to use for that column, you could directly use something likesid > 10.