user1435976
user1435976

Reputation:

Filter MySQL result w/ empty row

I have searched high and low to filter my mysql query but WHERE NOT NULL does not work. I hope somebody could help me. I have some columns that are empty named 'path'. And I want to filter these out.

My query:

SELECT 
p.path, p.title, p.body, p.post_date, u.username FROM pages p 
LEFT JOIN users u ON p.post_author = u.id 
ORDER BY p.id ASC

How can I get this done? Thanks.

Upvotes: 0

Views: 978

Answers (3)

Andrius Naruševičius
Andrius Naruševičius

Reputation: 8578

SELECT 
    p.path, p.title, p.body, p.post_date, u.username 
FROM pages p 
LEFT JOIN users u ON p.post_author = u.id
WHERE 
    p.path IS NOT NULL AND 
    p.path <> ''
ORDER BY p.id ASC

So does this help or you are asking something different?

Upvotes: 2

sephoy08
sephoy08

Reputation: 1114

Try this one, this might work.

SELECT 
p.path, p.title, p.body, p.post_date, u.username FROM pages p 
LEFT JOIN users u ON p.post_author = u.id 
WHERE p.path IS NOT NULL AND p.path <> ''
ORDER BY p.id ASC

Upvotes: 0

jogesh_pi
jogesh_pi

Reputation: 9782

try with php to check the empty field:

$query = "SELECT 
    p.path, p.title, p.body, p.post_date, u.username FROM pages p 
    LEFT JOIN users u ON p.post_author = u.id 
    ORDER BY p.id ASC";
$result = mysql_query($query);

while( $row = mysql_fetch_assoc($result) ){

// Check for empty record
if( !empty($row['path']) ){
    echo $row['path'];
   }
}

Upvotes: 0

Related Questions