如何将所有 +1 table 联合起来?
How to union all +1 table on this?
当前 SQL 查询:
SELECT question_ID,autor_id,titulo,pergunta,curtidas,comentario_ID,comentario_question_ID,comentario_autor_id,comentario,comentario_curtidas FROM
perguntador as a
LEFT OUTER JOIN perguntadorrespostas
ON perguntadorrespostas.comentario_question_id = a.question_id
UNION ALL
SELECT question_ID,autor_id,titulo,pergunta,curtidas,comentario_ID,comentario_question_ID,comentario_autor_id,comentario,comentario_curtidas FROM perguntador as b
RIGHT OUTER JOIN perguntadorrespostas
ON perguntadorrespostas.comentario_question_id = b.question_id order by question_ID desc
需要添加:
SELECT Nome,NULL...... FROM login
INNER (OR OTHER) JOIN perguntador ON perguntador.autor_id = login.user_id
这可能吗?
一些细节:
尝试过各种方式,但是 SELECT * FROM login
"intrude" 与其他 "SELECT"...(例如:[question_ID] 变成 [Nome] )
所需行:
[姓名]
在var_dump -> [Nome]=> [NULL]
最终结果:注意:未定义索引:Nome in....
我觉得很复杂,但是要花钱 我试试看有没有天才看懂的
这个"confusion cake"
P.S: 任何订单详情都将被受理,谢谢!
更新 1:Table 登录
- 名字
- 用户照片
- 不需要更多 7 列
Table perguntador
- question_ID
- autor_ID
- 标题
- 佩尔贡塔
- 柯蒂达斯
Table perguntadorrespostas
- comentario_ID
- 评论_question_ID
- comentario_autor_id
- 评论
- comentario_curtidas
图形说明
您需要 LEFT JOIN
您的 login
table 到您的 perguntador
table 查询并将您的 Nome
添加到 SELECT
-
SELECT
user_ID, Nome, userphoto, question_ID, autor_id, titulo,pergunta, curtidas,comentario_ID, comentario_question_ID, comentario_autor_id, comentario, comentario_curtidas
FROM
perguntador as a
LEFT OUTER JOIN
perguntadorrespostas
ON
perguntadorrespostas.comentario_question_id = a.question_id
LEFT OUTER JOIN
login
ON
a.autor_id = login.user_id
UNION ALL
SELECT
user_ID, Nome, userphoto, question_ID, autor_id, titulo, pergunta, curtidas, comentario_ID, comentario_question_ID, comentario_autor_id, comentario, comentario_curtidas
FROM
perguntador as b
RIGHT OUTER JOIN
perguntadorrespostas
ON
perguntadorrespostas.comentario_question_id = b.question_id
LEFT OUTER JOIN
login
ON
perguntadorrespostas.comentario_autor_id = login.user_id
ORDER BY
question_ID desc
当前 SQL 查询:
SELECT question_ID,autor_id,titulo,pergunta,curtidas,comentario_ID,comentario_question_ID,comentario_autor_id,comentario,comentario_curtidas FROM
perguntador as a
LEFT OUTER JOIN perguntadorrespostas
ON perguntadorrespostas.comentario_question_id = a.question_id
UNION ALL
SELECT question_ID,autor_id,titulo,pergunta,curtidas,comentario_ID,comentario_question_ID,comentario_autor_id,comentario,comentario_curtidas FROM perguntador as b
RIGHT OUTER JOIN perguntadorrespostas
ON perguntadorrespostas.comentario_question_id = b.question_id order by question_ID desc
需要添加:
SELECT Nome,NULL...... FROM login
INNER (OR OTHER) JOIN perguntador ON perguntador.autor_id = login.user_id
这可能吗?
一些细节:
尝试过各种方式,但是 SELECT * FROM login
"intrude" 与其他 "SELECT"...(例如:[question_ID] 变成 [Nome] )
所需行:
[姓名]
在var_dump -> [Nome]=> [NULL]
最终结果:注意:未定义索引:Nome in....
我觉得很复杂,但是要花钱 我试试看有没有天才看懂的
这个"confusion cake"
P.S: 任何订单详情都将被受理,谢谢!
更新 1:Table 登录
- 名字
- 用户照片
- 不需要更多 7 列
Table perguntador
- question_ID
- autor_ID
- 标题
- 佩尔贡塔
- 柯蒂达斯
Table perguntadorrespostas
- comentario_ID
- 评论_question_ID
- comentario_autor_id
- 评论
- comentario_curtidas
图形说明
您需要 LEFT JOIN
您的 login
table 到您的 perguntador
table 查询并将您的 Nome
添加到 SELECT
-
SELECT
user_ID, Nome, userphoto, question_ID, autor_id, titulo,pergunta, curtidas,comentario_ID, comentario_question_ID, comentario_autor_id, comentario, comentario_curtidas
FROM
perguntador as a
LEFT OUTER JOIN
perguntadorrespostas
ON
perguntadorrespostas.comentario_question_id = a.question_id
LEFT OUTER JOIN
login
ON
a.autor_id = login.user_id
UNION ALL
SELECT
user_ID, Nome, userphoto, question_ID, autor_id, titulo, pergunta, curtidas, comentario_ID, comentario_question_ID, comentario_autor_id, comentario, comentario_curtidas
FROM
perguntador as b
RIGHT OUTER JOIN
perguntadorrespostas
ON
perguntadorrespostas.comentario_question_id = b.question_id
LEFT OUTER JOIN
login
ON
perguntadorrespostas.comentario_autor_id = login.user_id
ORDER BY
question_ID desc