Hristo
Hristo

Reputation: 6540

MySQL SELECT with fields less and greater than values

I am trying to do a select query on MySQL with phpMyAdmin or PHP with PDO.

SELECT 'uid' FROM 'clusters' WHERE 'lat'<='47.21125' AND 'lat'>='39.21125' AND 'lng'<='32.90243' AND 'lng'>='22.90243'

However, phpMyAdmin says:

#1064 - 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 ''clusters' WHERE 'lat'<='47.21125' AND 'lat'>='39.21125' AND 'lng'<='32.90243' A' at line 1

What is wrong with it?

Upvotes: 5

Views: 46203

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

'' creates a string literal in MySQL, so your query is selecting the literal "uid" from the literal "clusters," which is invalid. Use backtics (or nothing)

SELECT Uid FROM clusters WHERE lat <= 47.21125 AND lat >= 39.21125
AND lng >= 22.90243

Upvotes: 10

Related Questions