SQL WHERE with AND

  • Ok I am having trouble getting a query accepting an AND statement with a literal 'string' in it. I have no trouble with either condition on its own but I cant get to an AND statement. Any good examples?


    try (ResultSet result = db1.executeQuery("SELECT playerID FROM Plowner WHERE ID = ' " +areaID+ " ' AND group = 'Red' ") ){


    If I cut down to just the Where and one of the conditions it works fine.

  • It's not caused by the AND, it's caused by "group", since that's a reserved keyword in SQL. If you want to use reserved words for column names, you have to use backticks in your SQL statement ;)
    SELECT playerID FROM Plowner WHERE ID = '"+areaID+"' AND `group` = 'Red'

  • Thanks Red ..as always ask the expert. It was driving me crazy. I have not read/come across about reserved words in SQL . That is the trouble with learning programming by ear. :S:thumbup:


    Not one of the tutorials I looked at talked about that. I thought it was a Java syntax thing going on. But now doing a Keyword/Reserved SQL search they fall out of the sky like dogs and cats.. thanks again

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!