At the moment I am revising my sql. I wish to perform a query in a table of items, where I would like to get the cheapest sweets.
select min(cost)
from items
where name like '%sweets%' and seller_id
in (
select seller_id
from items
where name like '%sweets%')
The above result, returns the cheapest price.
Problem:
I would like to display the name of the sweets, for example it may be chocolate sweets or strawberry sweets, etc. but if i change the first line of the query to select name, min(cost) the following error is produced:
Column 'items.name' is invalid in the select list because it is not contained
in either an aggregate function or the GROUP BY clause.
Now I am viewing MYSQL tutorials but I am working on sql server. It worked fine in the tutorial but not in my case
This will give you all fields in the cheapest row(s), not just cost:
BTW, a suffix search
LIKE %somethingwill cause a full table scan (and correspondingly poor performance).