Solved

Records with field not null

Posted on 2009-07-01
6
261 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 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