gpt4 book ai didi

php - 在 2 个表中列出成员的所有内容(问题、答案)

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:22 26 4
gpt4 key购买 nike

想要列出一个人的所有问题和所有答案。
我不知道我应该使用还是内部选择。

问题
id - 成员 - 问题 - 标题

Tbananswers
id - 成员 - 答案 - 标题

只需要获取每张表的标题

最佳答案

试试这个查询:

SELECT id,member,'Q' as Type, question as QA FROM Tbquestions
WHERE member='member1'
UNION ALL
SELECT id,member,'A' as Type, answer as QA FROM Tbanswers
WHERE member='member1'

示例输出:

id   member   Type   QA
1 Name1 Q What is it?
3 Name4 Q Who are you?
1 Name2 A My name is Name2
4 Name3 A He is dead, Jim.

编辑

为每个查询添加了 Limit 子句以查找 5 个问题和 10 个答案:

SELECT id,member,'Q' as Type, question as QA FROM Tbquestions
WHERE member='member1' LIMIT 5
UNION ALL
SELECT id,member,'A' as Type, answer as QA FROM Tbanswers
WHERE member='member1' LIMIT 10

关于php - 在 2 个表中列出成员的所有内容(问题、答案),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22827882/

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