两个类似的SQL查询返回不同的结果

时间:2012-05-23 14:09:01

标签: sql

大家好我有问题。

我有两个SQL查询都返回不同的结果:

SELECT name, capacity, $price, licensed, cost 
FROM venue, catering WHERE venue.venue_id = catering.venue_id 
AND grade=$grade 
AND capacity >= $minCapacity
AND capacity <= $maxCapacity
AND venue.venue_id 
NOT IN (SELECT venue_id FROM venue_booking WHERE date_booked = $us_date)

以及

SELECT venue.venue_id,name,capacity,licensed,$price,cost
FROM venue
JOIN catering ON venue.venue_id = catering.venue_id
WHERE capacity BETWEEN '$minCapacity' AND '$maxCapacity' 
AND venue.venue_id NOT IN 
(SELECT venue_id
FROM venue_booking
WHERE date_booked = '$us_date')
AND catering.grade = '$grade' ORDER BY venue.capacity

这有什么区别?

1 个答案:

答案 0 :(得分:5)

我的感受..主要区别是 -

在第一个查询中,您正在使用条件检查容量 -

AND capacity >= $minCapacity
AND capacity <= $maxCapacity

将作为号码申请..

但在第二个查询中,此条件在两个字符串值的范围内。