Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Mysql check if column is NULL how?

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Jawn

Straight from SwedenEstablished Member
Impact
2
Hi im trying to check if a column is = null but it doesnt seem to work anyone kn ow how?


SELECT * FROM images WHERE username = 'aaa' AND albumid = NULL ORDER BY id DESC LIMIT 0,20


Best Regards
Jawn
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
SELECT * FROM images WHERE username = 'aaa' AND WHERE albumid = '' ORDER BY id DESC LIMIT 0,20

Should work?
 
0
•••
I get


#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 'WHERE albumid = '' ORDER BY id DESC LIMIT 0,20' at line 1
 
0
•••
Jawn said:
I get


#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 'WHERE albumid = '' ORDER BY id DESC LIMIT 0,20' at line 1
albumid = '' <-- make sure you are using two single quotes. I beleive is right
 
0
•••
albumid = ''

is probably not valid SQL if albumid is an integer column.

I can't see why your original query doesn't work... what exactly is happening with it? Is it that you're just getting no items returned or are you getting a SQL error of some sort?
 
0
•••
It gets no items and its a integer column
 
0
•••
So just to be sure... are you certain the value in the column is NULL and not 0?

What happens if you use:
WHERE albumid = 0

instead?
 
0
•••
im 100% sure its NULL just checked with phpmyadmin
 
0
•••
Hmm... and I'm assuming you're using the PHPMyAdmin to run this query, right?

What happens if you use:
SELECT * FROM `images` WHERE `username` = 'aaa' AND `albumid` = NULL ORDER BY id DESC LIMIT 0,20

instead?

The backticks force MySQL to know that you are referring to column names.
 
0
•••
all of you are wrong.

IS NULL

SELECT * FROM images WHERE username = 'aaa' AND albumid IS NULL ORDER BY id DESC LIMIT 0,20

common mistake. above assumes that you are using a somewhat recent version of mysql.
 
0
•••
Luc said:
all of you are wrong.

IS NULL

SELECT * FROM images WHERE username = 'aaa' AND albumid IS NULL ORDER BY id DESC LIMIT 0,20

common mistake. above assumes that you are using a somewhat recent version of mysql.


thanks it works
 
0
•••
Eek... now that is embarrassing.

Good work Luc.
 
0
•••
TwistMyArm said:
Eek... now that is embarrassing.

Good work Luc.

nothing to be embarrassed about. i had the same problem a few months back when i moved from an old mysql version to a new one. the old used =, new used IS and things looked weird.

glad i could help.
 
0
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back