Jump to content

[SOLVED] Join tables and rename fields


dumdumsareyum

Recommended Posts

I have two columns "first_name" and "last_name" returned as a single column "name" . I only want the values of that occur in the table "employees" that don't occur in table "out_board".

 

So far I have this to return only the rows from employees that don't occur in out board:

 

SELECT employees.* AS name FROM employees LEFT JOIN out_board ON employees.id=out_board.id WHERE out_board.id IS NULL;

 

and this to combine the columns:

SELECT CONCAT_WS(" ", first_name, last_name) AS name FROM employees;

 

 

but I don't know how to combine the two so I only get the concatenated name column from my join.

 

Thanks!

 

 

Link to comment
https://forums.phpfreaks.com/topic/160209-solved-join-tables-and-rename-fields/
Share on other sites

SELECT CONCAT_WS(" ", a.`first_name`, a.`last_name`) as `name` FROM `employees` as a LEFT JOIN `out_board` as b ON a.`id`=b.`id` WHERE b.`id` IS NULL;

 

Alias the tables to save yourself some typing.  In the SELECT portion, you just identify which columns from which table you want, just like you always do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.