Forum Moderators: open
I want to select everyone who either has a null value or doesn't have a certain number there, but when I try to do a != comparison in the where clause it only picks the people who have no null value, so the whole load of people with null values doesn't show up when I do a != comparison. How do I get around this?
Thanks
if that doesn't do it, why don't you build a simple reproducable testcase (minimal create statements + select with joins) what we can test and work on?
//to make this script work just add the db "mydb" and change the host, user, and password
$host = "localhost";
$user = "root";
$pass = "";$conn = @mysql_connect("$host",
"$user", "$pass");
if (!$conn) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
// Select the player profile database
if (! @mysql_select_db("mydb") ) {
echo( "<P>Unable to locate the " .
"database at this time.</P>" );
exit();
}
mysql_query("CREATE TABLE `mydb`.`player_info` (
`pid` INT NOT NULL ,
`Name` TEXT NOT NULL ,
PRIMARY KEY ( `pid` )
)");
mysql_query("CREATE TABLE `mydb`.`playerActivities` (
`pid` INT NOT NULL ,
`aid` INT NOT NULL ,
PRIMARY KEY ( `pid` )
)");
mysql_query("INSERT INTO `mydb`.`player_info` (`pid` ,`Name`)
VALUES ('1', 'myName1'),
('2', 'myName2' ),
('3', 'myName3' )");
mysql_query("INSERT INTO `mydb`.`playerActivities` (`pid` ,`aid`)
VALUES ('1', '1'),
('2','2')");
//so player 1 has done activity 1 and
//player 2 has done activity 2 and
//player 3 has done nothing
//the following query should output player 2 and then player 3
//what it's doing now is only outputting player 2
$activityid = 1;
$sql = "SELECT * FROM player_info LEFT JOIN playerActivities ON player_info.pid=playerActivities.pid WHERE playerActivities.aid != $activityid AND playerActivities.aid IS NOT NULL";
$result = mysql_query( $sql );
while( $row = mysql_fetch_array( $result ) )
{
echo $row[Name];
echo "<br>";
}