如何获取MySQL上没有指定类别的记录?

时间:2019-02-28 07:48:28

标签: mysql

我有3张桌子。

SELECT id, name FROM entries LIMIT 3;
+----+----------------------------+
| id | name                       |
+----+----------------------------+
|  1 | I have a premium category. |
|  2 | I have no category.        |
|  3 | I have a normal category.  |
+----+----------------------------+

SELECT * FROM entries_categories LIMIT 3;
+----------+-------------+
| entry_id | category_id |
+----------+-------------+
|        1 |           1 |
|        1 |           2 |
|        3 |           2 |
|        3 |           3 |
+----------+-------------+

SELECT id, name, type FROM categories LIMIT 3;
+----+--------------------------+--------------+
| id | name                     | type         |
+----+--------------------------+--------------+
|  1 | premium                  |            1 |
|  2 | movie                    |            0 |
|  3 | game                     |            0 |
+----+--------------------------+--------------+

类型值只能是0或1。

现在,我想获取所有没有高级类别的完整内容

(这意味着没有类型1)。

最后我想获得这样的记录。

SELECT DISTINCT e.id, e.title, c.display_type FROM entries AS e
  INNER JOIN entries_categories AS ec ON e.id = ec.entry_id
  INNER JOIN categories AS c ON ec.category_id = c.id
  WHERE ????? <- I want to know this!!
;

+----+---------------------------+--------------+
| id | name                      | type         |
+----+---------------------------+--------------+
|  2 | I have no category.       |            0 |
|  3 | I have a normal category. |            0 |
+----+---------------------------+--------------+

我该怎么做?谢谢。

0 个答案:

没有答案