MySQL Forums
Forum List  »  Newbie

Display CONCAT() from second table if not NULL
Posted by: Christopher Esbrandt
Date: October 22, 2014 10:30AM

So, I've got a database that stores user data in its own table for use by anything that may need it. Then, a projects table with a column to identify the user assigned to the project, but it's nullable (in case someone hasn't been assigned it yet). When I need to to display the "last, first" from the users table if the assigned user ID isn't NULL.

Here's what I have for if all the projects have a user assign:

SELECT p.name, CONCAT(u.lastName, ', ', u.firstName) AS user, p.dueDate
FROM projects p, users u
WHERE p.uid = u.id
ORDER BY p.id DESC;

This results in no results when the p.uid is NULL, and I need it to still display the project, just leaving the field blank. Any ideas and what I can do?

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.