How to select records only in table b

Multi tool use
Multi tool use


How to select records only in table b



I have two tables. Table A and Table B. they both have two columns (Name and Salary). Both tables have duplicate name records but the salary is different. How can i write a query to select the name and salary of Table A where the name of table A is in table B's Name column.



MYSQL or MSSQL


Table A
Name Salary
john smith 100
john smith 100
sally smith 100
Dan smith 100


Table B
Name Salary
john smith 100
john smith 100
sally smith 100

result
Name Salary
john smith 100
john smith 100
sally smith 100





There EXISTS more than one way to JOIN these tables to understand the INNER details of the data.
– Sean Lange
Jun 29 at 19:40





can i use a join though if the data column i'm using in my on statement has duplicates in both tables?
– Steve Short
Jun 29 at 19:41





Your description and your title are totally different. This is one reason why sample data and desired results are so important.
– Gordon Linoff
Jun 29 at 19:42





Use JOIN TableB ON TableA.Name = TableB.Name
– iSR5
Jun 29 at 19:43


JOIN TableB ON TableA.Name = TableB.Name





i added some demo data
– Steve Short
Jun 29 at 19:46




1 Answer
1



Try this:


SELECT Name, Salary
FROM Table_A
WHERE Name IN (SELECT DISTINCT Name
FROM Table_B) ;






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

i9 NqUNtozL86rthmgLw6XV 2Y,dui
GyGuUYJoMNBNpp4pGKzj,UeDPxduape00kL SS A,pMQXJ hnkP,ekzu7gqz C5rG4k1,3Kle3B,cvGJXr1,Q8vLxWvtGdPdBv3mIpx

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya