在SQL查询中将IN值预先添加到表中

时间:2018-04-02 10:46:08

标签: mysql sql

您好有办法将IN值附加到结果表。

这是我的问题:

SELECT t.*,
       tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy IN ('nationality')
  AND tr.object_id IN (1099,
                       1401,
                       1646,
                       1087,
                       1610,
                       1293)
ORDER BY t.name ASC

我想将1099, 1401, 1646, 1087, 1610, 1293附加到非空的表结果中。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

只需将要查看的列添加到select命令的结果中:

    SELECT t.*,
           tt.*,
           tr.object_id
    FROM wp_terms AS t
    INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
    INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
    WHERE tt.taxonomy IN ('nationality')
      AND tr.object_id IN (1099,
                           1401,
                           1646,
                           1087,
                           1610,
                           1293)
    ORDER BY t.name ASC