logo

Back to questions

Easy SQL JOIN Practice Exercise SQL Interview Question

Easy SQL JOIN Practice Exercise

SQL Interview Question

Assume you're given the tables containing info about Robinhood users, and the stock trades they placed.

Use a to output all the information from the trades table joined to the users table.

Table:

Column NameType
order_idinteger
user_idinteger
pricedecimal
quantityinteger
statusstring('Completed' ,'Cancelled')
timestampdatetime

Example Input:

order_iduser_idpricequantitystatustimestamp
1001011119.8010Cancelled08/17/2022 12:00:00
10010211110.0010Completed08/17/2022 12:00:00
1002591485.1035Completed08/25/2022 12:00:00
1002641484.8040Completed08/26/2022 12:00:00
10030530010.0015Completed09/05/2022 12:00:00
1004001789.9015Completed09/09/2022 12:00:00
10056526525.605Completed12/19/2022 12:00:00

Table:

Column NameType
user_idinteger
citystring
emailstring
signup_datedatetime

Example Input:

user_idcityemailsignup_date
111San Franciscorrok10@gmail.com08/03/2021 12:00:00
148Bostonsailor9820@gmail.com08/20/2021 12:00:00
178San Franciscoharrypotterfan182@gmail.com01/05/2022 12:00:00
265Denvershadower_@hotmail.com02/26/2022 12:00:00
300San Franciscohoustoncowboy1122@hotmail.com06/30/2022 12:00:00

Example Output:

order_iduser_idquantitystatusdatepriceuser_idcityemailsignup_date
10010211110Completed08/17/2022 12:00:0010.00111San Franciscorrok10@gmail.com08/03/2021 12:00:00
10010111110Cancelled08/17/2022 12:00:009.80111San Franciscorrok10@gmail.com08/03/2021 12:00:00
10090014850Completed07/14/2022 12:00:009.78148Bostonsailor9820@gmail.com08/20/2021 12:00:00
10025914835Completed08/25/2022 12:00:005.10148Bostonsailor9820@gmail.com08/20/2021 12:00:00
10026414840Completed08/26/2022 12:00:004.80148Bostonsailor9820@gmail.com08/20/2021 12:00:00
10077717860Completed07/25/2022 17:47:003.56178San Franciscoharrypotterfan182@gmail.com01/05/2022 12:00:00
10040017832Completed09/17/2022 12:00:0012.00178San Franciscoharrypotterfan182@gmail.com01/05/2022 12:00:00
1005652652Completed09/27/2022 12:00:008.70265Denvershadower_@hotmail.com02/26/2022 12:00:00
10143226510Completed08/16/2022 12:00:0013.00265Denvershadower_@hotmail.com02/26/2022 12:00:00
10030530015Completed09/05/2022 12:00:0010.00300San Franciscohoustoncowboy1122@hotmail.com06/30/2022 12:00:00
10253348825Cancelled11/10/2022 12:00:0022.40488New Yorkempire_state78@outlook.com07/03/2022 12:00:00
1009094881Completed07/05/2022 12:00:006.50488

Difficulty

Easy

Input

(PostgreSQL)

Output