0

I want to supply a list of names like: 'car','red'.

I have 2 tables:

A
id
b_id

B
id
name

I want to be able to select record and order them by a list:

SELECT * 
FROM a  
JOIN b ON b.id = a.b_id 
ORDER BY b.name IN ('car','red') 
LIMIT 5

If the names are not in the list, then they appear after the items in the list, they do not get excluded.

I tried the above query, but it just gives me random items. The list is arbitrary and I must reference them by name. How can I do this when I only have that list.

S-Man
  • 22,521
  • 7
  • 40
  • 63
jas
  • 580
  • 1
  • 7
  • 18
  • Please show us some data and the expected output. – S-Man Mar 23 '20 at 14:42
  • Does this answer your question? [ORDER BY the IN value list](https://stackoverflow.com/questions/866465/order-by-the-in-value-list) – JGH Mar 23 '20 at 14:53
  • its close, but the problem is I have to generate the join data with code, so it different – jas Mar 24 '20 at 00:13

0 Answers0