dm03514
dm03514

Reputation: 55962

MySQL sql syntax error LIKE statement and conditionals

Perhaps a fresh set of eyes could help me with this. I thought this error corresponded to the AND OR statements but I switched things around and Still recieved the same error. Does someone see what is wrong with the following statement? Thank you. The query works fine without the like clauses.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%castillo% OR p.city LIKE %castillo% OR p.country LIKE %castillo% ) GROUP BY ima' at line 1

SELECT p.id, p.name, p.city, p.country, images.name as image, MIN(images.position) as position FROM properties as p, property_images as images WHERE p.id = \images.property_id AND p.is_active = 1 AND ( p.name LIKE %castillo% OR p.city LIKE %castillo% OR p.country LIKE %castillo% ) GROUP BY images.property_id

Upvotes: 0

Views: 1374

Answers (1)

Paul Dixon
Paul Dixon

Reputation: 300845

Try putting some quotes around your string literals, e.g.

SELECT p.id, p.name, p.city, p.country, images.name as image, MIN(images.position) as position 
FROM properties as p, property_images as images
WHERE p.id = images.property_id 
  AND is_active = 1 
  AND ( p.name LIKE '%castillo%' OR p.city LIKE '%castillo%' OR p.country LIKE '%castillo%' ) 
GROUP BY images.property_id

Upvotes: 2

Related Questions