Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mysql command for showing a single column from two table (same named column in both table) with using two different condition

The database name is employee-information in that database I was trying to show one "person_name" column that is available in both tables "works" & "employee" by using two different conditions that will filter values in each table.
So that I can see the values filtered by the two conditions from both tables in one single "person_name" column.

work & employee tables,

employee table data

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

work table data

Here is what I have done so far,

USE employee_information;

SELECT employee.person_name, works.person_name 
FROM employee, works
WHERE city = "Miami" AND salary > 50000;

The result I am getting,

For that command I am getting this two-column from both table. Conditions are working but values are repetitive and there are two columns but I need to show one column filled with the value from both tables where those two conditions are true

For that command I am getting this two-column from both table. Conditions are working but values are repetitive and there are two columns but I need to show one column filled with the value from both tables where those two conditions are true

My desired result is,

person_name//table name
Alex      //values those are true by both condition in each table 
Robin Hood

>Solution :

You need to join the tables using person_name as the relationship.

SELECT employee.person_name
FROM employee 
JOIN works ON employee.person_name = works.person_name
WHERE employee.city = 'Miami' AND works.salary < 50000;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading