
我不知道你的两个表怎么关联的,都有一个categoryname 字段,是通过它关联的吗,那可以这样:
select * from tb_category, tb_topic
where tb_category.categoryname = tb_topic.categoryname
and tb_category.groups = 1
补充:
写SQL都是自己想当然的写了让机器执行看看,结果可以了就行,你大胆的去想,例如:
select * from tb_topic
where categoryid in (select id from tb_category where tb_category.groups = 1)
update user u1 set u1.jifen=nvl((select sum(level) from sys_kaka s where id in (select id from user) and s.pid=2),0)*10按我所理解的大致是这样了
多表查询是指基于两个和两个以上的表或是视图的查询.在实际应用中,查询单个表可能不能满足你的需求,(如显示sales部门位置和其员工的姓名),这种情况下需要使用到(dept表和emp表)
自连接是指在同一张表的连接查询
select * from emp where empno=(select mgr from emp where ename='ford')
子查询是指嵌入在其它sql查询语句中的select语句,也叫嵌套查询
单行子查询是 指只返回一行数据的子查询语句
select * from emp where deptno=(select deptno from emp where ename='smith')
多行子查询指返回多行数据的子查询 使用关键字 in
如果我们的一个子查询,返回的 结果是多列,就叫做列子查询
合并多个select语句的结果,可以使用集合 *** 作符 union,union all
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)