Field Concatenation

Using the previous example where the three tables were joined together using an inner join, the data output can be improved upon to make more information fit on the page, by concatenating the output. In the results below, there is no need to have separate columns for first names and surnames so these have been concatenated.

It is possible to record the data within one field within the database, but it is prudent to keep the source data separate as it allows the flexibility to produce a mailmerge at a later date.

As the data in fields trans_cust_id and cust_id are both identical due to the matching performed on the join, The cust_id field has been removed to save space.


The code within the query is as follows, complete with 'c' and 's' in use as an alias for the respective Customer and Staff tables:

MySQL Code

CONCAT(c.cust_salutation, ' ',c.cust_firstname,' ',c.cust_surname) AS cust_fullname
CONCAT(s.staff_salutation,' ',s.staff_firstname,' ',s.staff_surname) AS staff_fullname

If the database being used was an MS-SQL database, this would be achieved as follows:

T-SQL (MS SQL)

c.cust_salutation + ' ' + c.cust_firstname + ' ' + c.cust_surname AS cust_fullname,
s.staff_salutation + ' ' + s.staff_firstname + ' ' + s.staff_surname AS staff_fullname

Live results from the MySQL database are below:


trans_cust_idcust_namecust_fullnametrans_grn_widgets_salestrans_blu_widgets_salesstaff_fullname
4589Wilton's Fine Products LtdMr Will Wilton500.000.00Mrs Anthea Allen
4583Quentin's Cabins LtdMr Quentin Quinn500.001800.00Mr Billy Beaumont
4568Billingham's of Braithwaite LtdMr Bertie Billingham1000.000.00Mr Charles Chuzzlewit
4570Dimbleby PLCMiss Diana Dimbleby2000.004500.00Miss Deirdrie Dawson
4582Peacock & Bradshaw LtdMr Peter Peacock2500.003000.00Mrs Francesca Faversham
4582Peacock & Bradshaw LtdMr Peter Peacock1000.001800.00Miss Gina Ginola
4587United Uniforms LtdMs Una Unsworth1500.00600.00Mrs Anthea Allen
4589Wilton's Fine Products LtdMr Will Wilton1500.00600.00Mr Billy Beaumont
4582Peacock & Bradshaw LtdMr Peter Peacock2000.00600.00Mr Charles Chuzzlewit
4568Billingham's of Braithwaite LtdMr Bertie Billingham2000.00600.00Miss Deirdrie Dawson
4568Billingham's of Braithwaite LtdMr Bertie Billingham1500.001200.00Mrs Francesca Faversham
4618Zen Products LtdMr Zane Zellweger1000.000.00Mr Billy Beaumont
4567Acorn Traders LtdMrs Anthea Adams3500.001200.00Miss Gina Ginola
4583Quentin's Cabins LtdMr Quentin Quinn1500.003600.00Mrs Anthea Allen
4584Rena's Supplies LtdMrs Rena Rimshaw1000.004000.00Mr Billy Beaumont
4583Quentin's Cabins LtdMr Quentin Quinn2500.00600.00Mr Charles Chuzzlewit
4585Shenley Shovels LtdMr Simon Sixsmith3000.003500.00Miss Deirdrie Dawson
4616X-cel LtdMrs Xaria Xanda2000.003000.00Mrs Francesca Faversham
4617Yeovil Yards LtdMr Yusef Yorke3000.003600.00Miss Gina Ginola
4618Zen Products LtdMr Zane Zellweger1500.001800.00Mrs Anthea Allen
4587United Uniforms LtdMs Una Unsworth1000.002400.00Mr Billy Beaumont
4589Wilton's Fine Products LtdMr Will Wilton3300.001200.00Mr Charles Chuzzlewit
4567Acorn Traders LtdMrs Anthea Adams1200.000.00Mr Billy Beaumont
4570Dimbleby PLCMiss Diana Dimbleby1500.00600.00Miss Deirdrie Dawson
4571East Empire LtdMs Elaine East3000.00600.00Mr Charles Chuzzlewit
4572Frannock Manor PLCMr Frederick Franklin2000.000.00Miss Deirdrie Dawson
4573Gimley of Gosborton LtdMr George Gimley3000.001200.00Mrs Francesca Faversham
4585Shenley Shovels LtdMr Simon Sixsmith1000.001800.00Mrs Anthea Allen
4582Peacock & Bradshaw LtdMr Peter Peacock1500.002400.00Mr Billy Beaumont
4618Zen Products LtdMr Zane Zellweger1000.003000.00Mr Billy Beaumont
4601Irlington Industries LtdMr Ian Icke1500.003000.00Mr Charles Chuzzlewit
4602Jeff Johnston LtdMr Jeff Johnston1000.001200.00Miss Deirdrie Dawson
4603Kensome & Kingston LtdMrs Karen Kensome1500.003000.00Mr Ernie Ecclestone
4616X-cel LtdMrs Xaria Xanda2000.001200.00Mrs Francesca Faversham
4582Peacock & Bradshaw LtdMr Peter Peacock500.002400.00Miss Gina Ginola
4583Quentin's Cabins LtdMr Quentin Quinn500.003600.00Mr Harry Harrison
4616X-cel LtdMrs Xaria Xanda2500.00600.00Mrs Anthea Allen
4572Frannock Manor PLCMr Frederick Franklin2500.00600.00Mr Billy Beaumont
4570Dimbleby PLCMiss Diana Dimbleby2000.00600.00Mr Billy Beaumont
4585Shenley Shovels LtdMr Simon Sixsmith2000.002400.00Mr Charles Chuzzlewit
4617Yeovil Yards LtdMr Yusef Yorke1500.003000.00Miss Deirdrie Dawson
4567Acorn Traders LtdMrs Anthea Adams1500.004200.00Mr Ernie Ecclestone
4571East Empire LtdMs Elaine East1500.001800.00Mrs Francesca Faversham
4572Frannock Manor PLCMr Frederick Franklin1500.001800.00Miss Gina Ginola
4591Yaxley Pies LtdMiss Yasmine Yolander1000.002400.00Mr Harry Harrison
4592Zimmerman's of Sawtry LtdMr Zak Zanetti1000.004800.00Mr Harry Harrison
4618Zen Products LtdMr Zane Zellweger2000.003400.00Mrs Anthea Allen
4601Irlington Industries LtdMr Ian Icke1500.003550.00Mr Billy Beaumont
4602Jeff Johnston LtdMr Jeff Johnston1500.003000.00Mr Charles Chuzzlewit
4603Kensome & Kingston LtdMrs Karen Kensome1500.003000.00Mr Charles Chuzzlewit
4583Quentin's Cabins LtdMr Quentin Quinn1500.002400.00Miss Deirdrie Dawson
4585Shenley Shovels LtdMr Simon Sixsmith2000.002400.00Mr Ernie Ecclestone
4617Yeovil Yards LtdMr Yusef Yorke2000.002400.00Mrs Francesca Faversham
4616X-cel LtdMrs Xaria Xanda2500.002400.00Miss Gina Ginola
4571East Empire LtdMs Elaine East2500.003600.00Mr Harry Harrison
4611Sally's Supplies LtdMrs Sally Smithers1500.003600.00Mrs Anthea Allen
4612Thompson's Tents LtdMr Toby Thompson1500.003600.00Mr Billy Beaumont
4613Ursula Umbridge LtdMrs Ursula Umbridge1500.003600.00Mr Charles Chuzzlewit
4603Kensome & Kingston LtdMrs Karen Kensome1500.001800.00Mr Charles Chuzzlewit
4616X-cel LtdMrs Xaria Xanda2000.001800.00Miss Deirdrie Dawson
4614Violet Vans LtdMrs Violet Vardy2000.001800.00Mr Ernie Ecclestone
4572Frannock Manor PLCMr Frederick Franklin1500.001800.00Mrs Francesca Faversham
4603Kensome & Kingston LtdMrs Karen Kensome1500.001800.00Miss Gina Ginola
4571East Empire LtdMs Elaine East1500.001800.00Mr Harry Harrison
4601Irlington Industries LtdMr Ian Icke1000.003000.00Miss Gina Ginola
4602Jeff Johnston LtdMr Jeff Johnston1000.003000.00Mr Harry Harrison
4603Kensome & Kingston LtdMrs Karen Kensome1000.003000.00Mrs Francesca Faversham
4583Quentin's Cabins LtdMr Quentin Quinn1000.002400.00Mr Ernie Ecclestone
4585Shenley Shovels LtdMr Simon Sixsmith1500.002400.00Mr Ernie Ecclestone
4612Thompson's Tents LtdMr Toby Thompson1500.001800.00Miss Deirdrie Dawson
4616X-cel LtdMrs Xaria Xanda1500.001800.00Mr Charles Chuzzlewit
4617Yeovil Yards LtdMr Yusef Yorke1500.001800.00Mrs Anthea Allen


Click the button below to advance to the next stage


Next: >> Grouping Customer Data


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