使用此SQL查询:
SELECT pictures.IMAGELINK,userdata.BIRTHDATE,userdata.POSITION,InfiniteLove.USERNAME FROM
InfiniteLove
LEFT JOIN pictures ON InfiniteLove.USERNAME = pictures.USERNAME
LEFT JOIN userdata ON InfiniteLove.USERNAME = userdata.USERNAME
WHERE NOT InfiniteLove.USERNAME = '".$USERNAME."' AND InfiniteLove.GENDER =
'M' AND InfiniteLove.SEARCH = 'M' OR InfiniteLove.SEARCH = 'B'
我得到了这个结果:
问题是,我只想要每个用户一行。 但是当用户有多张图片时,它会显示多行。
我能做什么,每个用户只能获得一行?
由于
答案 0 :(得分:-1)
添加GROUP BY
子句
SELECT pictures.IMAGELINK,userdata.BIRTHDATE,userdata.POSITION,InfiniteLove.USERNAME FROM
InfiniteLove
LEFT JOIN pictures ON InfiniteLove.USERNAME = pictures.USERNAME
LEFT JOIN userdata ON InfiniteLove.USERNAME = userdata.USERNAME
WHERE NOT InfiniteLove.USERNAME = '".$USERNAME."' AND InfiniteLove.GENDER =
'M' AND InfiniteLove.SEARCH = 'M' OR InfiniteLove.SEARCH = 'B'
GROUP BY InfiniteLove.USERNAME