Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! Can you tell me what is error there is in my query SQL?
I checked common number of each table's fields and check syntax, but i dont understand, how fix error.

Error Number: 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 'as ssss FROM typeorder UNION SELECT "estate", idTYPE, TYPENAME_AZ, T' at line 1


SQL
SELECT "type", idTYPEORDER AS "id", TYPEORDERNAME_AZ AS "name", TYPEORDERNAME_AZ as name_d, TYPEORDERNAME as name_ru, DEFAULT as ssss FROM typeorder
UNION
SELECT "estate", idTYPE, TYPENAME_AZ, TYPENAME_AZ,TYPENAME,DEFAULT FROM type_estate
UNION
SELECT "flats", idAPARTAMENT_FLATS, APARTAMENT_FLATSNAME_AZ, APARTAMENT_FLATSNAME_AZ, APARTAMENT_FLATSNAME, DEFAULT FROM apartament_flats
UNION
SELECT "currency", idCURRENCY, CURRENCYNAME_AZ, CURRENCYNAME_AZ, CURRENCYNAME, DEFAULT FROM currency
UNION
SELECT "country", idCOUNTRY, COUNTRYNAME_AZ, COUNTRYNAME_AZ, COUNTRYNAME , DEFAULTFROM country
UNION
SELECT "region", idREGION, REGIONNAME_AZ, REGIONNAME_AZ, REGIONNAME, DEFAULT FROM region
UNION
SELECT "city", idCITY, CITYNAME_AZ, CITYNAME_AZ, CITYNAME, DEFAULT FROM city
UNION
SELECT "village", idVILLAGE, VILLAGENAME_AZ,VILLAGENAME_AZ, VILLAGENAME, DEFAULT FROM village
UNION
SELECT "bedroom", idBEDROOM, BEDROOMNAME_AZ, BEDROOMNAME_AZ, BEDROOMNAME, DEFAULT FROM bedroom
UNION
SELECT "position", idPOSITION, POSITIONNAME_AZ, POSITIONNAME_AZ, POSITIONNAME, DEFAULT FROM position
UNION
SELECT "toilet", idTOILET, TOILETNAME_AZ, TOILETNAME_AZ, TOILETNAME, DEFAULT FROM toilet
UNION
SELECT "view", idVIEW, VIEWNAME_AZ, VIEWNAME_AZ, VIEWNAME, DEFAULT FROM view
UNION
SELECT "flat", idAPARTAMENT_FLAT, APARTAMENT_FLATNAME_AZ, APARTAMENT_FLATNAME_AZ, APARTAMENT_FLATNAME, DEFAULT FROM apartament_flat
UNION
SELECT "repair", idREPAIRTYPE, REPAIRTYPENAME_AZ, REPAIRTYPENAME_AZ, REPAIRTYPENAME, DEFAULT FROM repairtype
UNION
SELECT "project", idPROJECT, PROJECTNAME_AZ, PROJECTNAME_AZ, PROJECTNAME, DEFAULT FROM project
UNION
SELECT "rooms", idApartamentrooms, APARTAMENTROOMS_AZ, APARTAMENTROOMS_AZ, APARTAMENTROOMS, DEFAULT FROM apartament_rooms
UNION
SELECT "position_type", idPOSITION, POSITIONNAME_AZ, POSITIONNAME_AZ, POSITIONNAME, DEFAULT FROM position_type
UNION
SELECT "comfort", idCOMFORT, COMFORTNAME_AZ, COMFORTNAME_AZ, COMFORTNAME, DEFAULT FROM comfort
UNION
SELECT "metro", idMETRO, METRONAME_AZ, METRONAME_AZ, METRONAME, DEFAULT FROM metro ORDER BY name
Posted
Updated 21-Jun-13 9:58am
v2
Comments
Jardin1 20-Jun-13 11:55am    
And what is case for optimize this query? Instead _AZ possibility inserting "_RU", "_EN"
Mike Meinz 20-Jun-13 14:30pm    
Do you think the problem might be that DEFAULT is a reserved word and you are using it as the name of one of the columns in your database tables?

The rules for using UNION are:
(1) The number and the order of the columns must be the same in all queries,
(2) The data types must be compatible.

Make sure all of your SELECTs follow the rules.

Also, you spelled apartment wrong.

1 solution

First ... as Mike Meinz pointed out DEFAULT is a key word. Change the name of the columns on your database or (this is SQL Server but I think it works with MySQL) surround the column name with square brackets ... i.e. [DEFAULT]

Secondly... you are using UNION to join together queries containing very different data items ... flats & estates might go together, but putting toilets & rooms in there too????? If you want to "optimise" this query you will need to give hints of what you're actually trying to do with the results of this query ... at the moment it appears to be pointless.

Thirdly, learn that whitespace is your best friend, especially when you use tools that say things like "Error on line 6 near 'as ssss" ... so much easier to pinpoint the problem than "Error on line 1" (seriously, your DBMS really wants to say "somewhere in this very long line of text that no-one can read")

At the very least put some carriage returns around each UNION - I personally prefer having each clause (SELECT, FROM, UNION, ORDER BY etc) on a separate line - it's served me very well over the years to get straight to the problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900