Reputation: 1687
I need to order by where one column is exactly the same value as another column. Is there any way at all to do this? If there is, please let me know. ORDER BY wordMatch = wordCount
SELECT * ,
( input LIKE '% i %') +
( input LIKE '% love %' ) +
( input LIKE '% you %' ) AS wordMatch,
( LENGTH( input ) - LENGTH( REPLACE( input, ' ', '' ) ) -1 ) AS wordCount
FROM allData
HAVING wordMatch > ( wordCount * 0.6666 )
AND wordCount > ( 3 * 0.6666 )
ORDER BY wordMatch = wordCount
LIMIT 50
Upvotes: 3
Views: 51
Reputation: 1687
I was looking for something like this:
ORDER BY wordMatch = wordCount DESC , wordCount DESC
Upvotes: 0
Reputation: 1270713
If you want the closest matches first, then use desc
:
order by (wordMatch = wordCount) desc
Or, you might also want the absolute value of the difference:
order by abs(wordMatch - wordCount)
Upvotes: 1