gpt4 book ai didi

php - 如何选择某些元键的所有元值?

转载 作者:行者123 更新时间:2023-11-29 05:15:31 25 4
gpt4 key购买 nike

我正在尝试进行查询,但我无法掌握它。我想通过某些 meta_keys 选择所有记录。当我通过一个元键查询时它工作正常。但是当我想通过两个 meta_key 进行查询时,它什么都不返回。有人可以帮帮我吗?!

有效的查询:

SELECT *
FROM `uszc_users` AS u, `uszc_utilizatori_acord` AS ua, `uszc_usermeta` AS ub
WHERE ua.email = u.user_email
AND ub.user_id = u.id
AND ub.meta_key = 'first_name'
AND acord = 'DA'
LIMIT 0 , 30

以及不返回任何内容的查询:

SELECT *
FROM `uszc_users` AS u, `uszc_utilizatori_acord` AS ua, `uszc_usermeta` AS ub
WHERE ua.email = u.user_email
AND ub.user_id = u.id
AND ub.meta_key = 'first_name'
AND ub.meta_key = 'last_name'
AND acord = 'DA'
LIMIT 0 , 30

我有 3 个表,表 uszc_usermeta 包含 first_name 和 last_name,它们都在 meta_value 列中。

最佳答案

你不能有任何记录

AND ub.meta_key = 'first_name'
AND ub.meta_key = 'last_name'

没有意义,就这么简单:

SELECT *
FROM `uszc_users` AS u, `uszc_utilizatori_acord` AS ua, `uszc_usermeta` AS ub
WHERE ua.email = u.user_email
AND ub.user_id = u.id
AND (ub.meta_key = 'first_name'
OR ub.meta_key = 'last_name')
AND acord = 'DA'
LIMIT 0 , 30

更新 由于 OP 说 @bhelmet 发布了正确的答案,我想为 OP 澄清查询应该如何看起来像恕我直言:

SELECT u.*, ub.meta_value first_name, uc.meta_value last_name
FROM `uszc_users` AS u
INNER JOIN `uszc_utilizatori_acord` AS ua
ON ua.email = u.user_email
AND ua.acord = 'DA'
INNER JOIN `uszc_usermeta` AS ub
ON ub.user_id = u.id
AND ub.meta_key = 'first_name'
INNER JOIN `uszc_usermeta` AS uc
ON uc.user_id = u.id
AND uc.meta_key = 'last_name'
LIMIT 0 , 30

关于php - 如何选择某些元键的所有元值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33479959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com