Jump to content

What is wrong with this query?


mb81

Recommended Posts

(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

Link to comment
https://forums.phpfreaks.com/topic/63071-what-is-wrong-with-this-query/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.