mb81 Posted August 2, 2007 Share Posted August 2, 2007 (SELECT * FROM CLASSES_areas WHERE LENGTH(state1)>0) UNION (SELECT * FROM CLASSES_ares WHERE LENGTH(state2)>0) I am getting a syntax error right after UNION, what is wrong with this query? Here is the tables structure: CREATE TABLE `CLASSES_areas` ( `id` int(11) NOT NULL auto_increment, `areaname` varchar(100) NOT NULL default '', `shortname` varchar(50) NOT NULL default '', `state1` varchar(5) NOT NULL default '', `state2` varchar(5) NOT NULL default '', `state3` varchar(5) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=4 ; Any help would be really appreciated. Thanks, mb81 Quote Link to comment https://forums.phpfreaks.com/topic/63071-what-is-wrong-with-this-query/ Share on other sites More sharing options...
Tyche Posted August 2, 2007 Share Posted August 2, 2007 You refer to the table CLASSES_ares in the 2nd SELECT statement , This should be CLASSES_areas Quote Link to comment https://forums.phpfreaks.com/topic/63071-what-is-wrong-with-this-query/#findComment-314132 Share on other sites More sharing options...
mb81 Posted August 2, 2007 Author Share Posted August 2, 2007 You refer to the table CLASSES_ares in the 2nd SELECT statement , This should be CLASSES_areas Yes, I realized that once I posted it. There is, however, still a syntax error on the word UNION. Here is the code and the error again: SELECT * FROM CLASSES_areas WHERE LENGTH( state1 ) >0 UNION SELECT * FROM CLASSES_areas WHERE LENGTH( state2 ) >0 MySQL said: Documentation #1064 - You have an error in your SQL syntax near 'UNION SELECT * FROM CLASSES_areas WHERE LENGTH( state2 ) > 0' at line 1 It doesn't seem to matter what I include in parenthesis, even though that the MySQL 5.0 documentation said I should include the entire SELECT statement in parenthesis Quote Link to comment https://forums.phpfreaks.com/topic/63071-what-is-wrong-with-this-query/#findComment-314170 Share on other sites More sharing options...
fenway Posted August 2, 2007 Share Posted August 2, 2007 Not sure... I assume each one runs correctly on its own, you should try parens around each one... then explicity UNION DISTINCT. Quote Link to comment https://forums.phpfreaks.com/topic/63071-what-is-wrong-with-this-query/#findComment-314205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.