如何检查记录属于MySQL中的用户?

时间:2014-01-02 12:09:45

标签: mysql sql

我有一个SQL查询:

SELECT r.*, t.title, t.active, ticket_author.username as ticket_author, responser.username, responser.isAdmin, responser.isMod 
FROM `support_tickets_replies` r 
LEFT JOIN `support_tickets` t ON (t.id = r.tid) 
LEFT JOIN `users` ticket_author ON (ticket_author.id = t.uid) 
LEFT JOIN `users` responser ON (responser.id = r.uid) 
WHERE r.tid = [something goes here] 

我必须检查,该票证是否属于当前用户。用户ID位于t.uid。当它不是那个用户时,只返回“错误”列,并显示消息“禁止”。只能使用MySQL吗?

1 个答案:

答案 0 :(得分:1)

SELECT r.*, t.title, t.active, ticket_author.username as ticket_author, responser.username, responser.isAdmin, responser.isMod 
FROM `support_tickets_replies` r 
LEFT JOIN `support_tickets` t ON (t.id = r.tid) 
LEFT JOIN `users` ticket_author ON (ticket_author.id = t.uid) 
LEFT JOIN `users` responser ON (responser.id = r.uid) 
WHERE r.tid = [something goes here]
AND t.uid = [User ID goes here]

此查询仅会显示属于该用户的记录。 如果记录不属于用户,则不会返回任何内容。