If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SQL Syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-04, 08:32
Munti Munti is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
SQL Syntax

I've got some syntax problem with a query, but I get an error.

The query:

select * from table where field1 like '18%' and field1 like '19%' and field1 like '20%'

how is this done?

Børge
Reply With Quote
  #2 (permalink)  
Old 12-13-04, 08:51
bzakrzew bzakrzew is offline
Registered User
 
Join Date: Jan 2004
Location: Kennesaw, GA
Posts: 10
I can't find a syntax error with the above. I'd double check that your table name and field1 column name is entered correctly.

I do see a logic error, though. It is impossible to receive any matching rows for: field1 like '18%' AND field1 like '19%'. Field1 can't be 2 things at the same time. My guess is that you'd want to switch the "AND"s to "OR"s.
Reply With Quote
  #3 (permalink)  
Old 12-13-04, 13:20
Munti Munti is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Your're right, I'm not sure what I've been thinking, this syntax work perfectly;

SELECT * FROM tblMunicipal WHERE number LIKE '18%' OR number LIKE '19%' OR number LIKE '20%'

Thanks,
Børge

Last edited by Munti; 12-13-04 at 13:23.
Reply With Quote
  #4 (permalink)  
Old 12-13-04, 13:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
the query in post #3 will always return 0 rows
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On