| mySQL: Problem using UNION with SORT BY
|
joecap5

msg:4210927 | 5:11 am on Oct 4, 2010 (gmt 0) | I'm trying to get this query to work:
(SELECT A, B, D FROM table1 UNION ALL SELECT A, B, C FROM table2) SORT BY B I get an error though. It works when I take the SORT BY out:
SELECT A, B, D FROM table1 UNION ALL SELECT A, B, C FROM table2 but I want the query results sorted. Does anyone know what I'm doing wrong?
|
yaix2

msg:4210968 | 8:42 am on Oct 4, 2010 (gmt 0) | Isn't it "ORDER BY x DESC|ASC"?
|
LifeinAsia

msg:4211106 | 3:46 pm on Oct 4, 2010 (gmt 0) | Weclome [webmasterworld.com] to WebmasterWorld! Your parens are causing the error. Try: SELECT A, B, D FROM table1 UNION ALL SELECT A, B, C FROM table2 SORT BY B
|
joecap5

msg:4211310 | 12:42 am on Oct 5, 2010 (gmt 0) | You're both right! It is ORDER BY. I thought the parentheses were the right thing to do though. Can parentheses ever be used? Thanks
|
enigma1

msg:4211709 | 3:31 pm on Oct 5, 2010 (gmt 0) | | Can parentheses ever be used? |
| They could to define precedence for various operations but not to enclose the whole query eg: select a,b,c from table where a=1 and (b=2 or b=3)
|
LifeinAsia

msg:4211749 | 4:10 pm on Oct 5, 2010 (gmt 0) | | Can parentheses ever be used? |
| They can also be used to form an entity: SELECT * FROM MyTable WHERE ID=(SELECT Max(ID) FROM MyTable2)
|
|
|