Say if I have 2 tables. The first one holds users ids and their first names. The second one holds user ids and their last names, but the rows in this table may or may not exist depending on whether the user has given their last name or not.
I want to select both the first name and the last name, but if only the first name exists then to just select that on its own.
I cant use something like this because if the second table row doesn’t exist then it returns nothing:
$db->query("select firstname.fname, lastname.lname from firstname, lastname where firstname.userid = lastname.userid");
Thanks.
this will return something like:
where
NULLmeans that Bob hasn’t got a last nameJOINis more performant than cartesian product you are using in your example because it won’t produce all the possible combinations of{firstame,lastname}but just the ones which make sense (the ones with the same userid)