使用多个条件过滤 MySQL 查询
Filtering a MySQL query with multiple conditions
我的输出数组名为 "Feed Items" (fi):
(
[0] => Array
(
[reg] => 2015-08-03 13:39:00
[id] => fd7ec4107d16b07c1a13cbdd386af8d2cb05ffca
[user_id] => de5fd44db1760b006b1909cf1db11a78b38e455c
[img] => edee88e88cf6e17732e393b5433cfd894662902e
[type] => new_join_ambition
)
)
我生成了一个名为 "RemovedFeedItems" (rfi) 的数组,其结构如下:
(
[0] => Array
(
[object_id] => fd7ec4107d16b07c1a13cbdd386af8d2cb05ffca
[postee_id] => de5fd44db1760b006b1909cf1db11a78b38e455c
[type] => new_join_ambition
)
)
我的任务是不获取具有以下条件的记录:
ri.id == rfi.object_id && ri.user_id == rfi.postee_id && ri.type == rfi.type
我用来获取 Feed Items 数组的查询是:
SELECT
i.registered AS reg,
a.id,
u.id AS user_id,
ui.image_id AS img,
'new_join_ambition' AS type,
FROM x_ambition_invites i
LEFT JOIN x_user u
ON i.to = u.id
LEFT JOIN x_user_images ui
ON u.id = ui.user_id
LEFT JOIN x_ambitions a
ON i.ambition_id = a.id
WHERE a.registered
BETWEEN '2014-07-21 14:25:03' AND '2015-08-05 12:04:41'
AND i.to != '8fa7a1679560876eaf2f8060abd916b692c719dc'
AND i.to IN ('de5fd44db1760b006b1909cf1db11a78b38e455c')
我如何调整我的查询以实现从 FeedItems 数组中删除指定记录的条件?
提前致谢。
尝试使用 内联 table:
SELECT ... FROM ... WHERE (a,b,c) NOT IN (SELECT a1, b1, c1 UNION SELECT a2, b2, c2 UNION SELECT...)
缺点是您必须构建一个大的查询字符串。 :-(
我的输出数组名为 "Feed Items" (fi):
(
[0] => Array
(
[reg] => 2015-08-03 13:39:00
[id] => fd7ec4107d16b07c1a13cbdd386af8d2cb05ffca
[user_id] => de5fd44db1760b006b1909cf1db11a78b38e455c
[img] => edee88e88cf6e17732e393b5433cfd894662902e
[type] => new_join_ambition
)
)
我生成了一个名为 "RemovedFeedItems" (rfi) 的数组,其结构如下:
(
[0] => Array
(
[object_id] => fd7ec4107d16b07c1a13cbdd386af8d2cb05ffca
[postee_id] => de5fd44db1760b006b1909cf1db11a78b38e455c
[type] => new_join_ambition
)
)
我的任务是不获取具有以下条件的记录:
ri.id == rfi.object_id && ri.user_id == rfi.postee_id && ri.type == rfi.type
我用来获取 Feed Items 数组的查询是:
SELECT
i.registered AS reg,
a.id,
u.id AS user_id,
ui.image_id AS img,
'new_join_ambition' AS type,
FROM x_ambition_invites i
LEFT JOIN x_user u
ON i.to = u.id
LEFT JOIN x_user_images ui
ON u.id = ui.user_id
LEFT JOIN x_ambitions a
ON i.ambition_id = a.id
WHERE a.registered
BETWEEN '2014-07-21 14:25:03' AND '2015-08-05 12:04:41'
AND i.to != '8fa7a1679560876eaf2f8060abd916b692c719dc'
AND i.to IN ('de5fd44db1760b006b1909cf1db11a78b38e455c')
我如何调整我的查询以实现从 FeedItems 数组中删除指定记录的条件?
提前致谢。
尝试使用 内联 table:
SELECT ... FROM ... WHERE (a,b,c) NOT IN (SELECT a1, b1, c1 UNION SELECT a2, b2, c2 UNION SELECT...)
缺点是您必须构建一个大的查询字符串。 :-(