Need SQL Help

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

I need to select a row where a certain field is NOT LEFT EMPTY... Let's say I have the following Database Structure...
Code: [ Select ]
CREATE TABLE IF NOT EXISTS `wd_sitereviews` (
`RID` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(75) NOT NULL,
`email` varchar(75) NOT NULL,
`site` varchar(75) NOT NULL,
`notes` longtext NOT NULL,
`review` longtext NOT NULL,
PRIMARY KEY (`RID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  1. CREATE TABLE IF NOT EXISTS `wd_sitereviews` (
  2. `RID` int(11) NOT NULL AUTO_INCREMENT,
  3. `name` varchar(75) NOT NULL,
  4. `email` varchar(75) NOT NULL,
  5. `site` varchar(75) NOT NULL,
  6. `notes` longtext NOT NULL,
  7. `review` longtext NOT NULL,
  8. PRIMARY KEY (`RID`)
  9. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

In that, if the field 'review' is filled in then that would mean that there was already a review on that site and all I can do with it is read it... but if the 'review' is not filled in, I need that to be under a different category... I'm not sure how to do that...

Any help here? I'm sure the solution is easier than what I make it out to be... but I can't think at the moment...

Something like...
Code: [ Select ]
$sql = "SELECT * FROM " . SREVIEWS . " WHERE review <> null";

... ?

Thanks in advance :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Well according to your schema, none of your fields are allowed to be NULL. Fix that first.

You're close with the query:
Code: [ Select ]
SELECT * FROM wd_sitereviews WHERE review NOT NULL;
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

Alright, my table schema is:
Code: [ Select ]
 
CREATE TABLE IF NOT EXISTS `wd_sitereviews` (
  `RID` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(75) NOT NULL,
  `email` varchar(75) NOT NULL,
  `site` varchar(75) NOT NULL,
  `notes` longtext NOT NULL,
  `review` longtext,
  PRIMARY KEY (`RID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
  1.  
  2. CREATE TABLE IF NOT EXISTS `wd_sitereviews` (
  3.   `RID` int(11) NOT NULL AUTO_INCREMENT,
  4.   `name` varchar(75) NOT NULL,
  5.   `email` varchar(75) NOT NULL,
  6.   `site` varchar(75) NOT NULL,
  7.   `notes` longtext NOT NULL,
  8.   `review` longtext,
  9.   PRIMARY KEY (`RID`)
  10. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

And using your query, I get
Quote:
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 'NULL' at line 1

I implement it like:
Code: [ Select ]
$sql = "SELECT * FROM " . S_REVIEWS . " WHERE review NOT NULL";
 
$result = mysql_query($sql);
  1. $sql = "SELECT * FROM " . S_REVIEWS . " WHERE review NOT NULL";
  2.  
  3. $result = mysql_query($sql);

I don't know whats the deal here... any help would be great.

[EDIT:] Nevermind... the following works
Code: [ Select ]
SELECT * FROM " . S_REVIEWS . " WHERE review IS NOT NULL
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

I was close :)
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

spork wrote:
I was close :)

Yup :D Close enough

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 115 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.