Link to home
Start Free TrialLog in
Avatar of katlees
katleesFlag for United States of America

asked on

Records with field not null

I have this code SELECT * FROM Events WHERE CornPalace='1' AND APPROVED='1'  ORDER BY RAND() Limit 5 - how do I get it to only pull up the records where Image3FileName is not empty?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

simply add that condition
SELECT * FROM Events WHERE CornPalace='1' AND APPROVED='1' AND  Image3FileName IS NOT NULL ORDER BY RAND() Limit 5 

Open in new window

SELECT *
FROM Events
WHERE CornPalace='1' AND
APPROVED='1' AND
(Image3FileName IS NOT NULL or  Image3FileName <> '')
 ORDER BY RAND() Limit 5
I meant to say "AND":

SELECT *
FROM Events
WHERE CornPalace='1' AND
APPROVED='1' AND
Image3FileName IS NOT NULL AND  
Image3FileName <> ''
ORDER BY RAND() Limit 5  
Avatar of katlees

ASKER

When I try
SELECT * FROM Events WHERE CornPalace='1' AND APPROVED='1' AND  Image3FileName IS NOT NULL ORDER BY RAND() Limit 5

I still get records where Image3FileName is blank. I even ran it in the PHPMyAdmin and got the same results
Changing it to SELECT * FROM Events WHERE CornPalace='1' AND APPROVED='1' AND  Image3FileName <> ORDER BY RAND() Limit 5 gives me a blank page and an SQL error in PHPMyAdmin
Error is
SQL query:  

SELECT *
FROM EVENTS WHERE CornPalace = '1'
AND APPROVED = '1'
AND Image3FileName <> 
ORDER BY RAND( )
LIMIT 5

MySQL said:  

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY RAND() Limit 5' at line 1

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of katlees

ASKER

Thank you.