sql查询多表排序

来源:百度知道 编辑:UC知道 时间:2024/05/22 20:42:22
Table1
Id nun paixu
1 Sdfsd 4
2 Fsdf 5
3 Fsdf 3
4 Sdf 1
5 Sdfdfg 2
table2
id table1_id num
1 3 sdfsdf
2 3 sdfsdf
3 3 sdfsdf
4 1 sdfsdf
5 1 sdfsdf
6 1 sdfsdf
7 1 sdfsdf
8 1 sdfsdf
9 2 sdfsdf
10 2 sdfsdf
11 2 sdfsdf
12 2 sdfsdf
13 2 sdfsdf

我想 查处表table2的 记录 但是 想 按 表table1的排序方式输出
字段Table1_id为表table1的 id sql语句如何写 我用的 是 acc数据库
某某虫 非常感谢 我在补充一点 希望你来 看下 如果在给 table2加上 id>3 and id<6 怎么加呀

select table2.* from table2 inner join table1 on table2.table1_id = table1.id order by table1.paixu

就像你写的这样,直接加过滤条件就可以 但是要在字段前加表名前缀以区分两个表的ID字段
select table2.* from table2 inner join table1 on table2.table1_id = table1.id order by table1.paixu where table2.id > 3 and table2.id < 6

直接查询table2,order by table1_id asc 就行了

路过看到了,参考我的语句,应该可以的

SELECT 商品表.商品编号,sum(库存表.数量) as 库存数
FROM 库存表 LEFT JOIN 商品表 ON 库存表.商品编号 = 商品表.商品编号 group by 商品表.商品编号,库存表.数量;

select * from table2 order by table1_id

不用关系到table1