2016-05-12 165 views
-1

查詢數據我有三個表:約束,車站和時間PHP - 似乎無法從表

界有2列:boundID和boundName

站有3列:的stationID工作站名稱boundID

時間有4列:timeID departureTime tramID stationID

我正在使用此查詢來獲取boundName,但似乎無法獲取數據。任何幫助,將不勝感激!

$query ="SELECT b.boundName, s.stationName, t.departureTime 
    from Station s, Time t, Bound b 
    where s.stationID = t.stationID 
    AND t.departureTime !='' 
    AND s.boundID = b.boundID 
    AND b.boundName"; 
    } 

感謝

+0

'和b.boundName'這不是條件; – itzmukeshy7

回答

0

和b.boundName不應該出現,因爲一個WHERE條件計算爲1或0所以個人陳述也應該這樣做,在你的陳述中肯定不會返回0或1。

1

你必須刪除最後一個: '和b.boundName'。

使用此:

$query ="SELECT bound.boundName FROM bound, station, time WHERE 
station.stationID = time.stationID AND time.departureTime !='' AND 
station.boundID = bound.boundID"; 

或者這樣:

$query ="SELECT b.boundName, s.stationName, t.departureTime 
    from Station s, Time t, Bound b 
    where s.stationID = t.stationID 
    AND t.departureTime !='' 
    AND s.boundID = b.boundID"; 
0

如果使用加入試試這個

SELECT 
    `time`.`departureTime` 
    , `station`.`stationName` 
    , `bound`.`boundName` 
FROM 
    `test`.`station` 
    LEFT JOIN `test`.`bound` 
     ON (`station`.`boundID` = `bound`.`boundID`) 
    LEFT JOIN `test`.`time` 
     ON (`time`.`stationID` = `station`.`stationID`);