Reputation: 1705
Using the following query I need to display only the records marked with the year "2014" in the month "02":
SELECT DISTINCT
c.sno,
c.cCode,
c.caseNumber,
c.dateOriginalInstitution,
c.date_remanded,
c.plaintiff,
c.respondant
FROM
cases c,
chronologicallists ch
WHERE (
(YEAR(dateOriginalInstitution) = '2014' AND MONTH(dateOriginalInstitution) = '02')
OR
(YEAR(dateOfTransferInstituion) = '2014' AND MONTH(dateOfTransferInstituion) = '02')
OR
(YEAR(date_restored) = '2014' AND MONTH(date_restored) = '02')
)
AND c.inTheCourt = '578' AND c.sno = ch.caseSno
I'm still getting 2011 and 2012 in the result set?
Please help me with this.
Upvotes: 0
Views: 350
Reputation: 2713
There are 3 columns responsible for this dateOriginalInstitution
,dateOfTransferInstituion
,dateOfTransferInstituion
that you should check
Use AND
instead of OR
and mind to display dateOfTransferInstituion
for you to know if
they passed your WHERE
condition.
WHERE (
(YEAR(dateOriginalInstitution) = '2014' AND MONTH(dateOriginalInstitution) = '02')
AND
(YEAR(dateOfTransferInstituion) = '2014' AND MONTH(dateOfTransferInstituion) = '02')
AND
(YEAR(date_restored) = '2014' AND MONTH(date_restored) = '02')
Upvotes: 0
Reputation: 24002
It is because of your OR
condition.
You might be having year
value as 2014
in either dateOfTransferInstituion
or date_restored
columns but not in dateOriginalInstitution
column
Upvotes: 5