SQL error beyond me

Discussion in 'Databases' started by stevejoseph, Jul 21, 2010.

  1. #1
    I am attempting to perform the following MySQL query

    SELECT * FROM listings WHERE
    keywords like '%user%' or org like '%user%'
    AND
    town like '%LON%' or country like '%LON%' or postcode like '%LON

    I have added the line breaks in the query for clarity.

    suppose i run a query (one that works unlike the one above) i want to perform such that it returns record #1 only and not #2

    ID KEYWORDS ORG POSTOCE CITY COUNTY
    1 user CCS group dwddwwd LONDON UK
    2 Another CCS group xxxx LON UK
    3 user Counter strike xxxx Aberdeen UK
    4 Me Counter strike xxxx Aberdeen UK
    5 me Counter strike xxxx Aberdeen UK

    How can i acheive this, whats my error in the above query?
     
    Last edited: Jul 21, 2010
    stevejoseph, Jul 21, 2010 IP
  2. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #2
    Try to use brackets. I believe the query should be:


    SELECT * FROM listings WHERE 
    (keywords like '%user%' or org like '%user%')
    AND 
    (town like '%LON%' or country like '%LON%' or postcode like '%LON%)
    Code (markup):
     
    aquilax, Jul 21, 2010 IP