有两个表,第一个表Table1字段有ID,NewsID,NewsTitle.第二个表Table2字段有ID,NewsID,NewsTag要查询表一中NewsTitle对应的表二中NewsTag
注意:NewsTag可能是多个,但只对应一个NewsID.
要输出的结果是:只显示一个NewsTitle,显示全部表二中所有对应该NewsID的NewsTag.
sql如何一对多联合查询
答案:6 悬赏:80 手机版
解决时间 2021-03-05 00:33
- 提问者网友:嘚啵嘚啵
- 2021-03-04 12:42
最佳答案
- 五星知识达人网友:由着我着迷
- 2021-03-04 13:24
SELECt t1.NewsTitle,t2.NewsTag FROM table1 t1 , table2 t2
WHERe t1.NewsID=t2.NewsID
ORDER BY t1.NewsTitle
至于希望怎么显示在页如隐藏多余的newstitle在页面上控制就行啊
WHERe t1.NewsID=t2.NewsID
ORDER BY t1.NewsTitle
至于希望怎么显示在页如隐藏多余的newstitle在页面上控制就行啊
全部回答
- 1楼网友:冷風如刀
- 2021-03-04 16:19
select table1.NewTitle ,table2.[NewID] from table1 join
table2 on table1.[ID]=table2.[ID]
- 2楼网友:野味小生
- 2021-03-04 16:00
SELECt t1.NewsTitle,t2.NewsTag FROM table1 t1 , table2 t2
WHERe t1.NewsID=t2.NewsID
ORDER BY t1.NewsTitle
- 3楼网友:怀裏藏嬌
- 2021-03-04 15:38
有两个表,第一个表Table1字段有ID,NewsID,NewsTitle.第二个表Table2字段有ID,NewsID,NewsTag要查询表一中NewsTitle对应的表二中NewsTag
注意:NewsTag可能是多个,但只对应一个NewsID.
要输出的结果是:只显示一个NewsTitle,显示全部表二中所有对应该NewsID的NewsTag.
select 'NewsTitle' as 'NewsTitle',b.NewsTag
from table1 a,table2 b
where a.NewsTitle=b.NewsTag
order by b.NewsTag
- 4楼网友:天凉才是好个秋
- 2021-03-04 15:11
select t1.id, t1.name, t2.type
from t1 left outer join t2 on t1.id = t2.id and t2.pid = '1'
要是只显示t2中pid的奇数时
select t1.id, t1.name, t2.type
from t1 left outer join t2 on t1.id = t2.id and t2.pid%2 = 1
这时可以得出你想要的结果.
不知你想要的是不是这样的编辑.
希望能给你点帮助...
- 5楼网友:廢物販賣機
- 2021-03-04 15:01
sql 语句是这样写:
sql="select time,content,b.classname from record a left join class b on a.class_id=b.id"
下面是在ASP页面用来显示的:(创建那个与数据连接的对象不用写了吧)
<TABLE>
<%
set rs=conn.execute(sql) 执行上面的语句
do while not rs.eof
%>
<TR>
<TD><%=rs("time")%></TD>
<TD><%=rs("content")%></TD>
<TD><%=rs("classname ")%></TD>
</TR>
<%
rs.movenext
loop
%>
</TABLE>
如果你是oracle中:
select 人名,sum(sale) from (select a.id,a.sale,b.人名 from s a,p b where a.who=b.id(+)) group by 人名
在sql 和access:
select 人名,sum(sale) from (select a.id,a.sale,b.人名 from s a left join p b on a.who=b.id(+)) group by 人名
其中 a,b 是表s,表p的别名
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯