+ 2

Sql question !

the query below..the result will show just one record because of the MIN function ?? : SELECT name, MIN (cost) from items where name like '%book' AND seller_id IN (68,6,18);

15th Aug 2017, 10:47 PM
De Vinci
2 Answers
+ 7
Yes, the aggregation functions (sum, min, max, avg, count, etc.) only result in 1 row. If you use them with "group by" then each row for a "group".
16th Aug 2017, 3:49 AM
BĂ ng Tứ Cường
BĂ ng Tứ Cường - avatar
+ 1
As long as I know: Yes. But a bit more simple would be: SELECT name, cost FROM items WHERE name LIKE '%book' AND seller_id IN (68,6,18) ORDER BY cost LIMIT 1; (the default ORDER BY is ascending)
15th Aug 2017, 11:42 PM
Michal PĂĄcal
Michal PĂĄcal - avatar