设:
A表:3条记录。字段:userId,userName,userPw,SendNums(默认为0)
B表:1条记录。字段:QuserId,Qtitle,QContent
查询条件:b.QuserId =1 and SendNums=最小的数
想得到的查询结果:B表中有几条记录,就匹配出几条结果。
我现在的sql语句:
select a.userName,a.userPw,a.userId,a.SendNums,b.Id,b.QuserId,b.QTitle,b.QContent
from userInfo a LEFT JOIN Qnews b on QuserId='1' WHERE
a.SendNums=(select min(SendNums) from userInfo)
查询结果有3条记录。如果把其中一个a表的SendNums字段改成1,那么结果有2条记录。
如果想得到的查询结果:B表中有几条记录,就匹配出几条结果。应该怎么查?
------解决方案--------------------
改成这样呢:
select a.userName,a.userPw,a.userId,a.SendNums,b.Id,b.QuserId,b.QTitle,b.QContent
from userInfo a inner JOIN Qnews b on QuserId='1' WHERE
a.SendNums=(select min(SendNums) from userInfo)