Reputation: 23
I have a query in SQL
where I need to add a condition, to find all the records that have an empty field.
This gave me an error..
SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE SMS_MONTIME.IDTICKET ==''
Thanks
Upvotes: 2
Views: 3712
Reputation: 11599
to check an empty field, i.e NULL
field one can't use =
.
U have to use the IS NULL
Your query should be like this
SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET
WHERE SMS_MONTIME.IDTICKET IS NULL
Upvotes: 0
Reputation: 2802
In query use just =
for checking not ==
and for checking null values use is null
SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE SMS_MONTIME.IDTICKET ='' or SMS_MONTIME.IDTICKET is null
Upvotes: 1
Reputation: 425033
Try this:
...
WHERE SMS_MONTIME.IDTICKET = '' OR SMS_MONTIME.IDTICKET IS NULL
The issue is, what does "blank" mean: '' or null or more usually both
Also, use =
not ==
(I've never actually tried ==
, but I've never seen anyone else either, so it can't be good)
Upvotes: 1
Reputation: 1888
try this
"SELECT
forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma
LEFT JOIN
SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE SMS_MONTIME.IDTICKET =''"
or try this
WHERE SMS_MONTIME.IDTICKET is null
for not null use
WHERE SMS_MONTIME.IDTICKET is not null
Upvotes: 0