如何在3个表中选择distinct或union?避免重复数据

时间:2015-08-05 21:14:52

标签: php

我的代码是这样的,我坚持了几个小时:(在下面的查询中,数据显示是好的,但我想避免显示重复数据值,我想要区分用户的firstname和lastname以及来自的branch_name分支表。

select  *
from `user`,`appointment`,`branch`
where user.user_id = appointment.branch_id
   and branch.branch_id = appointment.branch_id

我想要区分用户的firstname和lastname以及分支中的distinct branch_name?我这样做了,

select  distinct user.firstname, user.lastname
from user
inner join appointment on appointment.user_id = user.user_id
inner join branch on branch.branch_id

我该怎么办?查询没问题,但是没有显示branch_name,因为我还要分开它,所以我这样做了,

select  distinct user.firstname, user.lastname
from user and branch.branch_name from branch
inner join appointment on appointment.user_id = user.user_id
    and branch.branch_id = appointment.branch_id

请帮助我,谢谢

0 个答案:

没有答案