473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Difference in SELECT WHERE IN with Datetime Fields

Anyone can explain the following?

Table definition:

CREATE TABLE testdate
(
SalesDate DATETIME,
SalesTotal DOUBLE,
PRIMARY KEY (SalesDate)
)

If I use the following SQL statement I get results:

SELECT * FROM testdate
WHERE SalesDate = '2003-08-27' OR SalesDate='2003-07-27';

But I get an empty set when I use this:

SELECT * FROM testdate
WHERE SalesDate IN ('2003-08-27', '2003-07-27');

This happens on both 4.0.15 and 3.23.57.
But the above statements work the same under Microsoft SQL Server.

Why is MySQL interpreting WHERE IN and WHERE = OR = differently?

Thanks,
Jul 19 '05 #1
2 14971
BDR
According to the manual, the IN search is performed using a binary
comparison, so it's possible I guess that the SalesDate column isn't
giving the correct output for the comp operation.

This does work though:
SELECT * FROM testdate
WHERE date_format(`SalesDate`,'%Y-%m-%d')
IN('2003-08-27', '2003-07-27');
Jim Min wrote:
Anyone can explain the following?

Table definition:

CREATE TABLE testdate
(
SalesDate DATETIME,
SalesTotal DOUBLE,
PRIMARY KEY (SalesDate)
)

If I use the following SQL statement I get results:

SELECT * FROM testdate
WHERE SalesDate = '2003-08-27' OR SalesDate='2003-07-27';

But I get an empty set when I use this:

SELECT * FROM testdate
WHERE SalesDate IN ('2003-08-27', '2003-07-27');

This happens on both 4.0.15 and 3.23.57.
But the above statements work the same under Microsoft SQL Server.

Why is MySQL interpreting WHERE IN and WHERE = OR = differently?

Thanks,


Jul 19 '05 #2
BDR
According to the manual, the IN search is performed using a binary
comparison, so it's possible I guess that the SalesDate column isn't
giving the correct output for the comp operation.

This does work though:
SELECT * FROM testdate
WHERE date_format(`SalesDate`,'%Y-%m-%d')
IN('2003-08-27', '2003-07-27');
Jim Min wrote:
Anyone can explain the following?

Table definition:

CREATE TABLE testdate
(
SalesDate DATETIME,
SalesTotal DOUBLE,
PRIMARY KEY (SalesDate)
)

If I use the following SQL statement I get results:

SELECT * FROM testdate
WHERE SalesDate = '2003-08-27' OR SalesDate='2003-07-27';

But I get an empty set when I use this:

SELECT * FROM testdate
WHERE SalesDate IN ('2003-08-27', '2003-07-27');

This happens on both 4.0.15 and 3.23.57.
But the above statements work the same under Microsoft SQL Server.

Why is MySQL interpreting WHERE IN and WHERE = OR = differently?

Thanks,


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jim Min | last post by:
Anyone can explain the following? Table definition: CREATE TABLE testdate ( SalesDate DATETIME, SalesTotal DOUBLE, PRIMARY KEY (SalesDate) )
2
by: Shaun | last post by:
Hi, I have a table called Bookings which has two important columns; Booking_Start_Time and Booking_End_Time. These columns are both of type DATETIME. Given any day how can I calculate how many...
2
by: Kieran Dutfield | last post by:
Code: ALTER PROCEDURE GetBookings ( @CurrentDate datetime, @Catergory char(10) ) AS SELECT BookingId, StartDate, PeriodStart, Catergory, Staff, Resource, Class, @CurrentDate AS Expr1
8
by: Paulo Jan | last post by:
Hi all: I have here a table with the following schema: Table "todocinetv" Column | Type | Modifiers...
2
by: Lad | last post by:
I use datetime class in my program and now I have two fields that have the datetime format like this datetime.datetime(2006, 5, 24, 16, 1, 26) How can I find out the date/time difference ( in...
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
5
by: Irfan Mughal | last post by:
i need ur help. i want to have CPU utilization of last 24 hrs. for time being i want to have result from 1 server. select "AVG_%_Total_Processor_Time", "WRITETIME", "MAX_...
5
by: bobh | last post by:
Hi All, Is there a difference in preformance between the two; TblNme has 36 fields across a record a query that selects all fields and the report only uses 75% of the fields, ie; Select...
1
by: Joey Fontaine | last post by:
I just noticed that, when using intellisense, the DateTime.MaxValue field has a static property icon whereas the Decimal.MaxValue field has a constant property icon. However, when looking at the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.