我已经创建了两个表的电话簿和座位。当我连接两个表的数据重复时,我不这样做。
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
公交簿表:
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或seat.seats进行连接的确切方案。
关于mysql - 在MySQL中联接表数据重复,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59211817/