我有两个表'user_detail'和产品表
'user_detail'
id email membership
1 x@gmail.com Premium
2 y@gmail.com Free
3 z@gmail.com Free
4 a@gmail.com Premium
5 c@gmail.com Free
'product'
id email Status Catgory Name
1 x@gmail.com Approved Agriculture Seed
2 y@gmail.com Approved Agriculture Grain
3 z@gmail.com Approved Agriculture Malt
4 a@gmail.com Approved Agriculture Fruit
5 c@gmail.com Approved Mobile iphone
告诉我查询我如何能够实现这个目标我希望显示这样的结果
批准的高级usr产品显示并显示免费的usr数据 意味着我想要像这样的数据
id Membership email Status Catgory Name
1 premium x@gmail.com Approved Agriculture Seed
4 premium a@gmail.com Approved Agriculture Fruit
2 free y@gmail.com Approved Agriculture Grain
3 free z@gmail.com Approved Agriculture Malt
pls help me to sort my problm ...
答案 0 :(得分:0)
您可以在email
列上加入两个表格,如
select ud.id,
ud.email,
p.Status,
p.Catgory,
p.Name,
ud.membership
from user_detail ud
join product p on ud.email = p.email
order by ud.membership desc;
答案 1 :(得分:0)
SELECT * FROM user_detail LEFT JOIN product ON product.email = user_detail.email;