Inner Join on Three Tables

This is an example of all three tables being joined together (Customer, Transactions and Sales). Now the data is joined to show the surname of the salesperson who made the sale to the customer. The output has been ordered by transaction id (ascending).



cust_idtrans_cust_idcust_namecust_firstnamecust_surnametrans_grn_widgets_salestrans_blu_widgets_salesstaff_surname
45894589Wilton's Fine Products LtdWillWilton500.000.00Allen
45834583Quentin's Cabins LtdQuentinQuinn500.001800.00Beaumont
45684568Billingham's of Braithwaite LtdBertieBillingham1000.000.00Chuzzlewit
45704570Dimbleby PLCDianaDimbleby2000.004500.00Dawson
45824582Peacock & Bradshaw LtdPeterPeacock2500.003000.00Faversham
45824582Peacock & Bradshaw LtdPeterPeacock1000.001800.00Ginola
45874587United Uniforms LtdUnaUnsworth1500.00600.00Allen
45894589Wilton's Fine Products LtdWillWilton1500.00600.00Beaumont
45824582Peacock & Bradshaw LtdPeterPeacock2000.00600.00Chuzzlewit
45684568Billingham's of Braithwaite LtdBertieBillingham2000.00600.00Dawson
45684568Billingham's of Braithwaite LtdBertieBillingham1500.001200.00Faversham
46184618Zen Products LtdZaneZellweger1000.000.00Beaumont
45674567Acorn Traders LtdAntheaAdams3500.001200.00Ginola
45834583Quentin's Cabins LtdQuentinQuinn1500.003600.00Allen
45844584Rena's Supplies LtdRenaRimshaw1000.004000.00Beaumont
45834583Quentin's Cabins LtdQuentinQuinn2500.00600.00Chuzzlewit
45854585Shenley Shovels LtdSimonSixsmith3000.003500.00Dawson
46164616X-cel LtdXariaXanda2000.003000.00Faversham
46174617Yeovil Yards LtdYusefYorke3000.003600.00Ginola
46184618Zen Products LtdZaneZellweger1500.001800.00Allen
45874587United Uniforms LtdUnaUnsworth1000.002400.00Beaumont
45894589Wilton's Fine Products LtdWillWilton3300.001200.00Chuzzlewit
45674567Acorn Traders LtdAntheaAdams1200.000.00Beaumont
45704570Dimbleby PLCDianaDimbleby1500.00600.00Dawson
45714571East Empire LtdElaineEast3000.00600.00Chuzzlewit
45724572Frannock Manor PLCFrederickFranklin2000.000.00Dawson
45734573Gimley of Gosborton LtdGeorgeGimley3000.001200.00Faversham
45854585Shenley Shovels LtdSimonSixsmith1000.001800.00Allen
45824582Peacock & Bradshaw LtdPeterPeacock1500.002400.00Beaumont
46184618Zen Products LtdZaneZellweger1000.003000.00Beaumont
46014601Irlington Industries LtdIanIcke1500.003000.00Chuzzlewit
46024602Jeff Johnston LtdJeffJohnston1000.001200.00Dawson
46034603Kensome & Kingston LtdKarenKensome1500.003000.00Ecclestone
46164616X-cel LtdXariaXanda2000.001200.00Faversham
45824582Peacock & Bradshaw LtdPeterPeacock500.002400.00Ginola
45834583Quentin's Cabins LtdQuentinQuinn500.003600.00Harrison
46164616X-cel LtdXariaXanda2500.00600.00Allen
45724572Frannock Manor PLCFrederickFranklin2500.00600.00Beaumont
45704570Dimbleby PLCDianaDimbleby2000.00600.00Beaumont
45854585Shenley Shovels LtdSimonSixsmith2000.002400.00Chuzzlewit
46174617Yeovil Yards LtdYusefYorke1500.003000.00Dawson
45674567Acorn Traders LtdAntheaAdams1500.004200.00Ecclestone
45714571East Empire LtdElaineEast1500.001800.00Faversham
45724572Frannock Manor PLCFrederickFranklin1500.001800.00Ginola
45914591Yaxley Pies LtdYasmineYolander1000.002400.00Harrison
45924592Zimmerman's of Sawtry LtdZakZanetti1000.004800.00Harrison
46184618Zen Products LtdZaneZellweger2000.003400.00Allen
46014601Irlington Industries LtdIanIcke1500.003550.00Beaumont
46024602Jeff Johnston LtdJeffJohnston1500.003000.00Chuzzlewit
46034603Kensome & Kingston LtdKarenKensome1500.003000.00Chuzzlewit
45834583Quentin's Cabins LtdQuentinQuinn1500.002400.00Dawson
45854585Shenley Shovels LtdSimonSixsmith2000.002400.00Ecclestone
46174617Yeovil Yards LtdYusefYorke2000.002400.00Faversham
46164616X-cel LtdXariaXanda2500.002400.00Ginola
45714571East Empire LtdElaineEast2500.003600.00Harrison
46114611Sally's Supplies LtdSallySmithers1500.003600.00Allen
46124612Thompson's Tents LtdTobyThompson1500.003600.00Beaumont
46134613Ursula Umbridge LtdUrsulaUmbridge1500.003600.00Chuzzlewit
46034603Kensome & Kingston LtdKarenKensome1500.001800.00Chuzzlewit
46164616X-cel LtdXariaXanda2000.001800.00Dawson
46144614Violet Vans LtdVioletVardy2000.001800.00Ecclestone
45724572Frannock Manor PLCFrederickFranklin1500.001800.00Faversham
46034603Kensome & Kingston LtdKarenKensome1500.001800.00Ginola
45714571East Empire LtdElaineEast1500.001800.00Harrison
46014601Irlington Industries LtdIanIcke1000.003000.00Ginola
46024602Jeff Johnston LtdJeffJohnston1000.003000.00Harrison
46034603Kensome & Kingston LtdKarenKensome1000.003000.00Faversham
45834583Quentin's Cabins LtdQuentinQuinn1000.002400.00Ecclestone
45854585Shenley Shovels LtdSimonSixsmith1500.002400.00Ecclestone
46124612Thompson's Tents LtdTobyThompson1500.001800.00Dawson
46164616X-cel LtdXariaXanda1500.001800.00Chuzzlewit
46174617Yeovil Yards LtdYusefYorke1500.001800.00Allen
MySQL Code

SELECT c.cust_id, t.trans_cust_id, c.cust_name, c.cust_firstname, c.cust_surname,
t.trans_grn_widgets_sales, t.trans_blu_widgets_sales, s.staff_surname
FROM customer AS c
INNER JOIN transactions AS t
ON c.cust_id = t.trans_cust_id
INNER JOIN staff AS s
ON t.trans_staff_id = s.staff_id
ORDER BY trans_id ASC
T-SQL (MS SQL)

SELECT c.cust_id, t.trans_cust_id, c.cust_name, c.cust_firstname, c.cust_surname,
t.trans_grn_widgets_sales, t.trans_blu_widgets_sales, s.staff_surname
FROM customer c
INNER JOIN transactions t
ON c.cust_id = t.trans_cust_id
INNER JOIN staff s
ON t.trans_staff_id = s.staff_id
ORDER BY trans_id ASC


Click the button below to advance to the next stage


Next: >> Field Concatenation


Or use the above 'SQL Queries' dropdown menu to jump to any stage.