WHERE col = NULL ?
Posted: Thu Jun 08, 2006 4:08 am
Weirdan | Please use
What I want to do is select all fields, and join the users data to it. But, when I do a WHERE on the user column, I only get results of fields that are already filled in, and that's not what I want. I want all fields, and if there's userdata, it should be there.
This is what I planned to do:
With this query, I only get results where a user matches (so I'm missing some field data). I thought I'd do this:
but that doesn't work neither.
Can anyone help me out?
Thanks in advance!
Weirdan | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a small query problem. First, these are my tables:
[syntax="sql"]CREATE TABLE `profile_fields` (
`field` VARCHAR( 255 ) NOT NULL ,
`type` VARCHAR( 255 ) NOT NULL ,
`size` INT( 3 ) NOT NULL ,
`max` INT( 5 ) NOT NULL ,
UNIQUE (
`field`
)
) ENGINE = MYISAM ;
CREATE TABLE `profile_data` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`user` VARCHAR( 32 ) NOT NULL ,
`field` VARCHAR( 255 ) NOT NULL ,
`value` TEXT NOT NULL ,
`timestamp` INT( 10 ) NOT NULL ,
INDEX ( `user` , `field` )
) ENGINE = MYISAM ;What I want to do is select all fields, and join the users data to it. But, when I do a WHERE on the user column, I only get results of fields that are already filled in, and that's not what I want. I want all fields, and if there's userdata, it should be there.
This is what I planned to do:
Code: Select all
SELECT *
FROM profile_fields
LEFT JOIN profile_data ON profile_fields.name = profile_data.field
WHERE profile_data.user = '$user'Code: Select all
SELECT *
FROM profile_fields
LEFT JOIN profile_data ON profile_fields.name = profile_data.field
WHERE
profile_data.user = '$user' OR
profile_data.user = NULLCan anyone help me out?
Thanks in advance!
Weirdan | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]