I've got a simple table that logs simple occasions webmaster does. Nothing complicated.

Among the posts is userid, in order to reference anyone's title in the customers table:

SELECT u.username FROM `users` u, `history` h WHERE u.userid = h.userid

My problem would be that the organs and circulatory system also logs occasions (as being a user), but there's no userid associated with the interior system. It's just drenched as zero, within the record.

It is possible to method to customize the query to mirror this? I have attempted a LEFT JOIN, but that does not allow me to specify "system" because the username. Another factor i'm able to do is enter a brand new user in to the user's table, and refer to it as "Organs And Circulatory SystemInch. However I really don't wish to do this.

Can you really do that in the query level?


   SELECT COALESCE(u.username, 'SYSTEM') AS username,
LEFT JOIN USERS u ON u.userid = h.userid

COALESCE will return the very first non-NULL value, if you LEFT JOIN onto Customers and username is NULL--then "system" or anything you prefer can look.