0

I am trying to create an app for the salespeople who work for my company to keep track of their sales/commission

When a salesperson brings on an account, their name is noted on the account and the table might look like

Table B

Account Salesperson
Account A A
Account B B
Account C B
Account D A

Then the jobs list might look like

Table A

Account Job details Price
Account A xyz £x
Account B xyz £x
Account C xyz £x
Account D xyz £x
Account A xyz £x
Account C xyz £x

I am looking for a way to filter the results of table A based on the sales person noted next to the Account in Table B

I have looked at all of the JOIN options but am unsure I am using the correct one.

I have opted, currently, for

SELECT J.*, A.Company, A.SalesPerson FROM TableA A
INNER JOIN TableB B
ON A.Account= B.Account
Where A.Salesperson = "B"

This seems to work for the time being, however I am unsure wether this is the best Join to use and whether it will last the test of time

J.D.
  • 40,776
  • 12
  • 62
  • 141
PaulMcF87
  • 177
  • 6

1 Answers1

1

Inner join is the correct type for what you described. Only rows that match the join expression will be included in the result.

You probably need an index to help optimize the join if the tables are expected to grow. I don't know what indexes you currently have in these tables, so I won't guess which index you need.

Bill Karwin
  • 16,963
  • 3
  • 31
  • 45