With a MySQL Query, If a Field has a particular value, then include it in the SELECT query otherwise, don't include it -
i have query , want include particular field in query, if field has particular value in it, otherwise, don't want include it.
so, example if table has:
id | title | liked | score 1 happy song 1 10 2 sad song 0 20 3 fun song 1 30 4 friendly song 0 15
my initial query be:
select * songs liked = '1' order id score desc limit 3;
however, if none of records returned had 1 in liked field or 1 of them did, still need 3 records returned , want return regular non-liked records.
is possible?
select * songs order liked desc, id, score desc limit 3
order liked desc
puts liked records first. if there @ least 3 liked records, shown. if there fewer, add non-liked records.
btw, if id
field unique, there's no point in having other fields after in order by
clause. later fields used when earlier fields have same value. want order liked desc, score desc
.
Comments
Post a Comment