mysql请求逻辑

时间:2015-02-14 21:49:13

标签: php mysql sql

我有3张桌子 和2个值

display.isUpload = 2

userId = 11(当前userId)

第一

Table Ask
id INT
userId INT
qask VARCHAR

第二

 Table Display
    id INT
    askId INT
    isUpload INT

第三

Table Push

    id INT
    displayId INT
    userId INT

逻辑询问显示为灰色列表,当用户选择其中一个时,它将记录到表推送。 现在我需要显示来自ask的所有记录,但不显示用户添加到push的记录(我不知道如何在我当前的请求中执行此操作)和display.isUploaded = 2以及ask.userId NOT IN 11.(我可以从删除中删除记录) 我当前的sql请求

                  SELECT
  a.id as id,
  a.qask as qask
  FROM Ask AS a
  JOIN Display AS d ON d.askId = a.id
  WHERE d.isUploaded = 2 AND
   a.userId  NOT IN (11)

2 个答案:

答案 0 :(得分:0)

你的意思是你想要这个(我添加了最后一行):

SELECT
  a.id as id,
  a.qask as qask
  FROM Ask AS a
  JOIN Display AS d ON d.askId = a.id
  WHERE d.isUploaded = 2 AND
   a.userId  NOT IN (11)
  AND a.userId NOT IN ( SELECT id from Push)

答案 1 :(得分:0)

你的问题不清楚,据我所知,我写了这个问题

SELECT
a.id AS id,
a.qask AS qask
FROM Ask AS a
LEFT JOIN Display AS d ON d.askId = a.id
LEFT JOIN Push AS p ON p.displayId = d.id
WHERE d.isUploaded = 2 
AND p.id=NULL
AND a.userId <>11