SQL: clause with newbie syntax error
i have this clause:
"Select *
From
(
Select sedi_i18n.*,
0 orden
From table sedi_i18n
Where culture= 'italiano'
Union
Select sedi_i18n.*, 1 orden
From table sedi_i18n
Where culture<> 'italiano'
)
Order By orden, culture";
But i'm getting this error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check开发者_高级运维 the manual that corresponds to your MySQL server version for the right syntax to use near 'table sedi_i18n Where culture= 'italiano' Union Select sedi_i18n.*, 1 or' at line 6
Any idea?
Regards
Javi
You need a subquery alias after your parenthesis, and to remove the word table - like so:
Select *
From
(
Select sedi_i18n.*,
0 orden
From sedi_i18n
Where culture= 'italiano'
Union
Select sedi_i18n.*, 1 orden
From sedi_i18n
Where culture<> 'italiano'
) SQ
Order By orden, culture;
0 orden
need to be
0 , orden
the same problem with
1 orden
1, orden
also fix @Stiivi remark
At first sight this looks like a problem:
From table sedi_i18n
should be:
From sedi_i18n
(without the 'table' word)
Same on line 6 and line 10.
do you require the word "table" in your statement? I recommend taking the union out and running it without it to see what you get. Break it down and see how where your real error is.
Get rid of the word "table" in your queries. Also alias the inner query.
"Select *
From
(
Select sedi_i18n.*,
0 orden
From sedi_i18n
Where culture= 'italiano'
Union
Select sedi_i18n.*, 1 orden
From sedi_i18n
Where culture<> 'italiano'
) a
Order By orden, culture";
精彩评论