Reputation: 715
I have a simple question. I have to join multiple queries and most of them has ad IN clausole. Unfortunally, MySQL doesn't allow ORDER BY in an UNION (only outside all unions) but I need a specific ordering that I can't get with an outside order by.
Question is: If I have a IN clausole like
foo in ('newyork','boston','atlanta')
may I assume MySql's engine will order the resulting rows by IN position (so, first all the row with foo = 'newyork' then 'boston' etc...
Thanks.
Upvotes: 0
Views: 55
Reputation: 115
Select *
from
(
Select * from Temp1
order by x
) Tbl1
UNION
Select *
from
(
Select * from Temp2
order by y
) Tbl2
Try this.
Upvotes: 1
Reputation: 39477
No. It's nothing like that. You need to explicitly add an order by clause.
If you want to order your rows based on position in a set, you can use field
function.
order by field(foo,'newyork','boston','atlanta')
Upvotes: 2