I know you can sort by the field, but can you sort by words specifically in the field. Say i want to sort by field X, but always list those that contain the word "apple" within field X first?
Use an IF() in your query's field list to make another result field for sorting, e.g.:
SELECT `a`, `b`, `c`, `X`, IF(`X` LIKE '%apple%', 1, 2) AS `X_sort` ORDER BY `X_sort` ASC, `X` ASC
Also, this has to do with the previous.
If there are multiple rows with the word "Apple" in a field, how would I get MySQL to randomly choose a row? I believe LIMIT 0,1 will only choose the first row in the structure every time.
Say if i look at two fields(A and 😎, and I search by field A. However, for the results that I get, some rows have the same B. How could I get MySQL to choose only one of each result with a given B.
If you only want one unique result per field, add a GROUP BY statement to group on that field.
thanks
Don't forget to mark this thread resolved (if it is).