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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.