Solved

Records with field not null

Posted on 2009-07-01
6
259 Views
Last Modified: 2012-05-07
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?
0
Comment
Question by:katlees
  • 2
  • 2
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24757636
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

0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24757661
SELECT *
FROM Events
WHERE CornPalace='1' AND
APPROVED='1' AND
(Image3FileName IS NOT NULL or  Image3FileName <> '')
 ORDER BY RAND() Limit 5
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24757675
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  
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:katlees
ID: 24757718
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

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24757756
blank and NULL is not the same thing
SELECT * FROM Events WHERE CornPalace='1' AND APPROVED='1' AND  Image3FileName IS NOT NULL 

AND Image3FileName != ''

ORDER BY RAND() Limit 5

Open in new window

0
 

Author Closing Comment

by:katlees
ID: 31598929
Thank you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now