Results 1 to 4 of 4

Thread: SQL Syntax

  1. #1
    Join Date
    Dec 2004
    Posts
    3

    Unanswered: 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

  2. #2
    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.

  3. #3
    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 14:23.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the query in post #3 will always return 0 rows
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •