SQL两张表一对多如何查询?

【编程】 SQL两张表一对多如何查询?

--------------------------------------------

傻大方资讯为您精选的网友回复(供您参考):

[电脑使用技巧]两张表,Goods商品表,Picture图片表。Goods表中含有这么两个字段:trumbnail,picture,分别是缩略图和大图,对应Picture表id。Picture表中有id,url。也就是说,一条商品记录,在Picture表中有两个记录,分别记录两个图的位置。请问如何在一条语句中将一个商品的两个图片都取出来?

--------------------------------------------

傻大方资讯为您精选的网友回复(供您参考):

[电脑使用技巧]join on 2次,,,我用sqlyog试试,,稍等,,,,SELECT p1.url AS 'trumbnail',p2.url AS 'picture'FROM goods AS g JOIN picture AS p1 ON g.trumbnail=p1.idJOIN picture AS p2 ON p2.id=g.picture附上效果图,,,

--------------------------------------------