gpt4 book ai didi

mysql - 如何组合两个简单的sql查询

转载 作者:太空宇宙 更新时间:2023-11-03 10:57:55 25 4
gpt4 key购买 nike

我有以下 sql 查询:

//Get id
SELECT id from magazine where name = 'Web Designer'


SELECT avatar from person where newsletter = 1 and id in
(
SELECT person_id as id FROM person_magazine WHERE magazine_id = 9 //use id from previous query
)

如何将它们结合起来,这样我就不必运行两个查询?

最佳答案

我认为您需要了解联接。以下是您真正想要的查询:

SELECT p.avatar
from person p join
person_magazine pm
on pm.person_id = p.id join
magazine m
on pm.magazine_id = m.id
where p.newsletter = 1 and m.name = 'Web Designer'

关于mysql - 如何组合两个简单的sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18596874/

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