Mysql多表查询

时间:2013-09-13 16:54:05

标签: mysql

我正在尝试获取唯一值,但我得到以下语句的多个值。

SELECT bd.sessionkey, 
       bd.booking_id, 
       Concat(cs.name, ' ', cs.surname) AS name, 
       cs.phone, 
       cs.id, 
       pikuppoint, 
       droppoint, 
       bd.pickupdate, 
       bd.pickuptime, 
       bc.booking_id, 
       bc.paymenttype, 
       bc.pay, 
       bc.paydate, 
       bc.payment_status, 
       bp.booking_id, 
       bp.adultpassenger, 
       bp.childrenpassenger, 
       bp.babies, 
       bp.children_age, 
       bp.babies_age, 
       bp.totalpassenger, 
       bp.babies_seat, 
       bp.biglugage, 
       bp.mediumlugage, 
       bp.smalllugage, 
       b.order_id, 
       b.site, 
       b.transferdirection_id, 
       b.customer_id, 
       b.cartype, 
       b.specialrequirment, 
       b.bookingdate 
FROM   customerdetails cs, 
       bookingpassengers bp, 
       booking b, 
       bookingcost bc, 
       bookingdetails bd 
WHERE  bp.booking_id = bc.booking_id 
       AND bp.booking_id = b.order_id 
       AND b.order_id = bd.booking_id 
       AND b.order_id = bc.booking_id 
       AND bd.booking_id = bp.booking_id 
       AND cs.id = b.customer_id 
       AND bd.pickupdate BETWEEN Date_sub(Curdate(), INTERVAL 0 day) AND 
                                 Date_add(Curdate(), INTERVAL 1 day) 
ORDER  BY bd.pickupdate, 
          bd.pickuptime, 
          id 
LIMIT  0, 15 

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

您的SELECT语句只是选择符合条件的所有值。

尝试使用SELECT DISTINCT

http://www.w3schools.com/sql/sql_distinct.asp