By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,576 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,576 IT Pros & Developers. It's quick & easy.

I need 'order' in a select w/ Union statement

P: 31
I've got a statement as follows that grabs matching records out two tables:

"SELECT * FROM BKRETAIL WHERE BKRETAIL.MATK='THISTHE' UNION SELECT * FROM BKMASTER WHERE BKMASTER.MATK='THISTHE';

My problem is that when I try to place something like "ORDER BY BKRETAIL.MEDSTA ASC" after the statement, it throws an error. I need these ordered in a certain arrangement. To be honest, what I really need is to order them by when MEDSTA's field is "RT" first, then "LW", then "OE", then null... but I haven't been able to figure out how to do that so I just put in an "ORDER BY" so the nulls would at least be at the end... Can anybody help me figure out how to order this list?? Thanks BUNDLES
Sep 11 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
In UNION, ORDER BY will be executed on the final resultset.

Try removing the qualifying name. Just the columnname.

ORDER BY MEDSTA ASC

-- CK
Sep 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.