Practice Center – inner join

Practice SQL inner joins online against a real database. Read the summary of each exercise carefully, enter the corresponding SQL query in the text box underneath and click on the submit button. When you click on submit, you will get an immediate feedback whether your query is right or wrong.

Exercise 1

Display in one query:

  • the client id (column client_id) and the phone number (column phone_number) of clients (table clients) that have a salesperson associated (table salespersons)
  • the first name and last name of the salesperson associated (salesperson_id from clients corresponds to id from salesperson)

In this query, do not display the salespersons without any clients



Submit

Exercise 2

Display in one query:

  • the client id (column client_id) and the phone number (column phone_number) of clients (table clients) that have no associated salesperson (salesperson_id=0) but a salesperson (table salespersons) in the same state (if there is more than one salesperson in the same state, put display more than one line per client)
  • the first name and last name of the salesperson in the same state


Submit

Exercise 3

Display in one query:

  • the client id (column client_id) of clients (table clients) that have no associated salesperson (salesperson_id=0, table salespersons) but a salesperson in the same state that has an amount of sales (column total_sales) strictly lower than 33000
  • the first name, last name, state and total sales of the salesperson associated


Submit

Exercise 4

Same as above, but be careful:

  • first_name of table salespersons and last_name of table salespersons appear as first_name_salesperson and last_name_salesperson in the result header
  • client_id appears as client_id and state as state


Submit

Exercise 5

Same as above, but your query must contain “from salespersons” instead of “from clients” and return the same result.

Submit

To practice SQL outer join: go to the SQL outer join practice.
For more exercises using a real database: full list of SQL practice exercise.
If you like the challenge: try to practice group by.

 
Share on:


Author:
Last udpated: March 1, 2018
Created: December 21, 2014