多表关联不显示重复列
- 1.使用:USING();
一般我们做关联查询的时候,都是select * from table1 inner join table2 on table1.XX=table2.XX,这样查询出的结果在展现的时候是有相同字段的,如果不想要的话,那么我们可以拿using(XX)取代 table1.XX=table2.XX,一样可以达到关联效果 - 多表关联:用USING(相同列名) ,会去除相同列名并形成新的视图,所以筛选的时候不需要用表名.列名的方式
SELECT *FROM Student
INNER JOIN SC USING(SID)
INNER JOIN Course USING(CID)
image.png
- 多表关联:用USING(相同列名) ,会去除相同列名并形成新的视图,所以筛选的时候不需要用表名.列名的方式
limit和top的使用方法
按行数做筛选查询
-
MySQL写法 : limit
table中的数据,从第10行开始顺位展现,一共展现两条!展现第11和第12行:
select * from table limit 10,2; -
SQLserver:top
table中的数据只展现10行
select top 10 * from table; -
SqlServer中如果要实现第10到12行这样中间行,这里需要用个嵌套;
select top 12* from table where id not in(select top 10 id from table )
意思就是:
① 先查询出top 10(前10行的id)
② 然后查询出前12行
③ 12行中排除id不等于前10行查询的出i
那么就剩下11和12行的数据了!

查询

多表关联方法

网友评论