這是我的數據庫表格表示。
我正在做inner join從這些表中獲取數據 的查詢如下。
查詢-1
select * from Trips
Inner join TripPoints
On Trips.tripkey=Trippoints.tripkey
inner join Cars
On Trips.carid=Cars.cid
and Cars.cid IN ('1','2','3','4','5','6')
where (lat>='4.0' and lat<='5.0')
and
(long>='52' and long <='54')
查詢-2
for(int carId=1;carId<=6;carId++)
{
select * from Trips
Inner join TripPoints
On
Trips.tripkey=TripPoints.tripkey
inner join Cars
on
Trips.carid=Cars.cid and CARS.cid = carId
where
(lat>='4.0' and lat<='5.0')
and
(long>='52' and long <='54')
}
兩個查詢執行成功。
但是查詢-1給出比更少的記錄查詢-2?
查詢有什麼區別會導致結果差異?
你使用哪個數據庫有'for'循環結構? – Oded
我使用C#構建sql查詢,數據庫是mySQL 5.0。 –