Combine statement but only need to get data based on WHERE column of table is empty

I have this query and only want to get records with a specific column empty ( volunteers_2009.venue_id

)

Table volunteers_2009

, column I'm looking to see if it's empty:venue_id

Here's the current request:

SELECT volunteers_2009.id, volunteers_2009.comments, 
   volunteers_2009.choice1, volunteers_2009.choice2, volunteers_2009.choice3, 
   volunteers_2009.lname, volunteers_2009.fname, volunteers_2009.venue_id, 
   venues.venue_name 
FROM volunteers_2009 AS volunteers_2009 
LEFT OUTER JOIN venues ON (volunteers_2009.venue_id = venues.id) 
ORDER by $order $sort

      

I am trying to do this:

SELECT volunteers_2009.id, volunteers_2009.comments, 
   volunteers_2009.choice1, volunteers_2009.choice2, volunteers_2009.choice3, 
   volunteers_2009.lname, volunteers_2009.fname, volunteers_2009.venue_id, 
   venues.venue_name 
FROM volunteers_2009 AS volunteers_2009 
LEFT OUTER JOIN venues ON (volunteers_2009.venue_id = venues.id) 
ORDER by $order $sort 
WHERE volunteers_2009.venue_id == ''

      

How do I display only records containing an empty column ( venue_id

) in a table ( volunteers_2009

)?

0


source to share


2 answers


WHERE clause doesn't work in your second query. It must come before the ORDER BY clause.

Also, I don't think you have empty id places. Perhaps you really want:

SELECT volunteers_2009.id, volunteers_2009.comments, 
    volunteers_2009.choice1, volunteers_2009.choice2, volunteers_2009.choice3, 
    volunteers_2009.lname, volunteers_2009.fname, volunteers_2009.venue_id, 
    venues.venue_name 
FROM volunteers_2009 
LEFT JOIN venues ON venue_id = venues.id
WHERE venues.id IS NULL
ORDER BY $order $sort

      

This will only return volunteers_2009 records that do not match locations.



Or that:

SELECT volunteers_2009.id, volunteers_2009.comments, 
    volunteers_2009.choice1, volunteers_2009.choice2, volunteers_2009.choice3, 
    volunteers_2009.lname, volunteers_2009.fname, volunteers_2009.venue_id, 
    venues.venue_name 
FROM venues
LEFT JOIN volunteers_2009 ON volunteers_2009.venue_id = venues.id
WHERE volunteers_2009.venue_id IS NULL
ORDER BY $order $sort

      

to find places without volunteers.

+2


source


By empty do you mean null? If the field venue_id

can contain zeros, you can compare using the operator is

like this:



WHERE volunteers_2009.venue_id is null

      

+4


source







All Articles