我有3个值:
两张桌子:
对象:
用户:
我想在以下情况下选择对象的名称:
什么sql语句可以帮到我?
答案 0 :(得分:1)
未经测试但应该有效。
SELECT
o.object_name
FROM
objects o
LEFT JOIN users u ON o.user_id = u.user_id
WHERE
o.objectId = 1
AND (
(u.email = ''
AND u.password = '')
OR o.user_id = 0
)
答案 1 :(得分:1)
只返回对象名称?
SELECT object_name
FROM objects o LEFT JOIN users u ON o.user_id = u.user_id
WHERE (u.email IS NOT NULL
AND u.password IS NOT NULL)
OR user_id = 0
答案 2 :(得分:1)
SELECT o.object_name FROM objects o
LEFT JOIN users u ON o.user_id=u.user_id
WHERE (u.email IS NOT NULL AND u.password IS NOT NULL)
OR o.user_id=0
我不确定你的意思是object_name还是object_id?
答案 3 :(得分:0)
SELECT
o.Name
FROM
Objects o
LEFT JOIN
Users u
ON
u.Id = o.UserId
WHERE
(u.Email = email
AND
u.Password = password)
OR
o.UserId = 0
答案 4 :(得分:0)
如果你想测试,我把对象放在SqlFiddle中。
http://sqlfiddle.com/#!2/86023/9
SELECT O.ID FROM OBJECTS O
WHERE O.ID IN (
SELECT U.ID FROM USERS U
WHERE U.USER = 'test' AND U.PASS = 'test'
)
OR O.USERID = 0