有2个表...
A表是产品表:
id name
1 a1
2 a2B表是产品订单表:
id name type
1 a1 0
2 a2 1
3 a1 1
4 a1 0我想这样列出A表数据,但是B表中type=0的排前面(A.name=B.name)应该怎么写
A表是产品表:
id name
1 a1
2 a2B表是产品订单表:
id name type
1 a1 0
2 a2 1
3 a1 1
4 a1 0我想这样列出A表数据,但是B表中type=0的排前面(A.name=B.name)应该怎么写
from A,B
where A.name =B.name
order by B.type
from A left join B on A.name=B.name
order by B.type
from A
order by (select type from B where name=A.name)
3楼的:Subquery returns more than 1 row 我在order by里加limit 1也没用...
select b.type,a.name from a join b on a.name=b.name
我的意思是
现在列出A表中所有产品信息但订单表中如果type=0的要在产品列表中排前面
from A,(select name,min(type) as type from B group by name) B1
where A.name = B1.name
order by B1.type
from A
order by (select min(type) from B where name=A.name)