开发者

Query not resulting correct records

开发者 https://www.devze.com 2023-02-25 18:56 出处:网络
I have this query: SELECT id, name FROM users WHERE ((id = 1) OR (5 <= 5)) This should result all records as 5 = 5, but it\'s not开发者_开发知识库. It\'s only resulting records where the id = 1.

I have this query:

SELECT id, name FROM users
WHERE ((id = 1) OR (5 <= 5))

This should result all records as 5 = 5, but it's not开发者_开发知识库. It's only resulting records where the id = 1.

What am I doing wrong?

EDIT: This is the full query:

SELECT project_id, project_name, project_description, project_active, 
            users.user_firstname, users.user_lastname FROM projects 
            INNER JOIN users ON projects.user_id = users.user_id 
            WHERE (projects.user_id = 1 || 3 <= 3)

EDIT: Found it =/ Something was wrong with the join; user_id didn't exist anymore for some reason.


Try:

EXPLAIN EXTENDED SELECT id, name FROM users where id=1 or 5<=5;

SHOW WARNINGS;

u will find mysql executes the query is:

SELECT id,name FROM users where 1

just means (id=1 or 5<=5) is same as 1


So do you want all records smaller or equal 5?

if so its only

SELECT id, name FROM users
WHERE id <= 5

Beside that

(5 <= 5)

is "5" a table row like id?


Do this

$q = ("SELECT id, name FROM users WHERE id = 1 || 5 <= 5");

This is how I do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消