我需要获取重复数据的空字段

例如,一个客户可以有两个或多个联系人,因此查询返回(只是将qyery resul缩短):

CUSTOMER_NAME | CONTACT_PERSON | ETC ..

  dell         |    Ighor      |etc..
  dell         |    Dima       |etc..


但我需要:
CUSTOMER_NAME | CONTACT_PERSON |等...

             dell         |    Ighor      |etc..
             NULL         |    Dima       |etc..


SELECT
             `contact`.*,
                 `branch_has_equipment`.*,
             `branch_has_contact`.*,
                         `equipment`.*,
                         `customer_has_branch`.*,
                         `branch`.*,
                         `customer`.*,
              `ip`.*

                 FROM `customer`
                 INNER JOIN `customer_has_branch`
                         ON `customer`.`customer_id` = `customer_has_branch`.`customer_id`
                 INNER JOIN `branch`
                         ON `customer_has_branch`.`branch_id` = `branch`.`branch_id`
                 INNER JOIN `branch_has_equipment`
                         ON `branch`.`branch_id` = `branch_has_equipment`.`branch_id`
                 INNER JOIN `equipment`
                         ON `branch_has_equipment`.`equipment_id` = `equipment`.`equipment_id`
                 INNER JOIN `branch_has_contact`
                         ON `branch`.`branch_id` = `branch_has_contact`.`branch_id`
                 INNER JOIN `contact`
                         ON `branch_has_contact`.`contact_id` = `contact`.`contact_id`

                INNER JOIN `equipment_has_ip`
                        ON `equipment`.`equipment_id` = `equipment_has_ip`.`equipment_id`
                INNER JOIN `ip`
                        ON `equipment_has_ip`.`equipment_id` = `ip`.`ip_id`

                 WHERE `customer`.`inservice` = 'Yes'
                         ORDER BY `customer`.`customer_name`


另外,表格^

顾客

客户ID
顾客姓名
服务中
服务类型
评论



branch_id

地址

设备

equipment_id

模型
connection_param
连接类型
序列号
ID
发布

联系

contact_id
名称

phone_mobile
phone_work
phone_other
位置

customer_has_branch_id
客户ID
branch_id

最佳答案

由于我不知道这些表中的任何一个如何相互关联,因此我唯一的答案是使用OUTER JOIN,它将保留NULL结果。

关于mysql - MySQL加入请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15503483/

10-10 23:04