gpt4 book ai didi

mysql - 如果使用 MySQL 存在行,则获取列?

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:37 24 4
gpt4 key购买 nike

我有两个表photosale

photo 有两列 idurl

sale 有两列 photoIDstatus

问题是,photo 表中的照片(行)不必在 sale 表中有记录,因此我们不知道照片是否在是否出售。

照片

id | url

1 | http://...

2 | http://...

3 | http://...

促销

photoID | status

1 | 'sold'

3 | 'pending'

如您所见,id 2 的照片在 sale 表中没有记录。我想要做的是从 photo 表中提取所有照片,如果在 sale 表中有它的记录,我想要 status信息也是如此,但在一个查询中。我怎样才能做到这一点?

谢谢。

最佳答案

   SELECT p.*, s.status 
FROM photo p
LEFT JOIN sale s
ON p.id = s.photoID

关于mysql - 如果使用 MySQL 存在行,则获取列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6845307/

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