首先,感谢您抽出宝贵时间阅读本文档
问题:
例
SELECT Article.ID, Article.Name, Article.Price, EV.EV, Pic.Upload_Datum
FROM Article
LEFT JOIN Pic ON Articel.ID = Pic.Artikle_ID
LEFT JOIN Stock ON Stock.ID = Article.Lager_ID
LEFT JOIN EV ON EV.ID = Article.EV_ID
WHERE Article.Activ = "1"
AND Stock.trader_ID = "2"
AND Article.stock_ID = "1"
AND pic.Uploaddate IS NOT BETWEEN 1510903702 AND 1503127702
LIMIT 10
示例结果
身份证上传
2624919 1489736525
2624919 1489736528
2624920 1507295386
2624920 1507295389
2624920 1507295397
多数民众赞成在我得到的结果之一,但我只需要这两个:
2624919 1489736525
2624920 1507295386
现在,我获得了foreach Article.ID多个记录,因为在“ pic”表中,任何文章都有多个图片。问题是,我只需要sql找到的第一张图片。
我希望这是正确的提问方式。
问候
B3rgi
最佳答案
如果您真的不关心要为图片拍摄的数据,请参见以下示例,它将拍摄您文章的第一张照片。
SELECT Article.ID, Article.Name, Article.Price, EV.EV,
SELECT Pic.Upload_Datum
FROM Pic
WHERE Articel.ID = Pic.Artikle_ID
LIMIT 1) AS Upload_Datum
FROM Article
LEFT JOIN Stock ON Stock.ID = Article.Lager_ID
LEFT JOIN EV ON EV.ID = Article.EV_ID
WHERE Article.Activ = "1"
AND Stock.trader_ID = "2"
AND Article.stock_ID = "1"
LIMIT 10
关于mysql - 一对多关系仅是众多关系中的一项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47346010/