连接Mysql中重复的表数据 [英] Join table data duplicate in Mysql

查看:52
本文介绍了连接Mysql中重复的表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个表 busbookseats.当我加入两个重复的表数据时,我不知道为什么.

I have created two tables busbook and seats. When I join two tables data duplicated I don't why.

SELECT seats.busno,
       seats.seats,
       busbook.status,
       busbook.customer,
       busbook.mobile,
       seats.date
FROM seats
     Left JOIN busbook ON  seats.busno=busbook.busno

这是我得到的输出:

busno  seats     status     customer         mobile    date
91000     1       Booked     ss              11      2019-12-06
91000     2       Booked     ss              11      2019-12-06
91000     3       Booked     ss              11      2019-12-06
91000     4       Booked     ss              11      2019-12-06
91000     5       Booked     ss              11      2019-12-06
91000     6       Booked     ss              11      2019-12-06
91000     7       Booked     ss              11      2019-12-06
91000     8       Booked     ss              11      2019-12-06
91000     9       Booked     ss              11      2019-12-06
91000    10       Booked     ss              11      2019-12-06

座位:

id    busno   seats       date
1     91000    1      2019-12-06
2     91000    2      2019-12-06
3     91000    3      2019-12-06
4     91000    4      2019-12-06
5     91000    5      2019-12-06
6     91000    6      2019-12-06
7    91000     7      2019-12-06
8    91000     8      2019-12-06
9    91000     9      2019-12-06
10   91000    10      2019-12-06
11   91000     11     2019-12-06
12   91000     12     2019-12-06

busbook 表:

id  busno   seat     status       customer       mobile        date
2   91000    1       Booked          ss            11          2019-12-06
3   91000    19      Booked          dd            22          2019-12-06

推荐答案

怎么样

SELECT seats.busno, seats.seats,busbook.status, busbook.customer,busbook.mobile,seats.date FROM seats 
Left JOIN busbook ON seats.busno=busbook.busno
AND seats.seats = busbook.seat

我想这取决于seat.id或seats.seats加入的确切方案

I guess it depends on what exactly scheme is to do join by seats.id or seats.seats

这篇关于连接Mysql中重复的表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆