Simple Table Lists

This is a simple demonstration of MySQL queries running live on a web-based database. The data has been returned to a PHP script and output to a web page using HTML, CSS and Javascript.



Listing the customers table

First off is a list of the first nine fields of the Customer table, ordering the results by customer ID.

The SQL code to achieve this is the same for both MySQL and T-SQL as shown:

MySQL Code and T-SQL Code (MS SQL)

SELECT cust_id, cust_name, cust_add1, cust_add2,
cust_add3, cust_county, cust_postcode, cust_salutation,
cust_firstname, cust_surname
FROM exc_customer
ORDER BY cust_id ASC

Only the first nine fields are listed due to the width of the HTML table that would be required for all fields:


cust_idcust_namecust_add1cust_add2cust_add3cust_countycust_postcodecust_salutationcust_firstnamecust_surname
4567Acorn Traders LtdFactory RoadBurwellCambridgeCambridgeshireCB5 0BNMrsAntheaAdams
4568Billingham's of Braithwaite LtdLow LaneBraithwaiteDoncasterSouth YorkshireDN10 4PXMrBertieBillingham
4569Colcon LtdGranite CloseEnderbyLeicesterLeicestershireLE3 2XFMrCecilCollins
4570Dimbleby PLCHallam MillHallam StreetStockportCheshireSK2 6PTMissDianaDimbleby
4571East Empire LtdWigwam LaneHucknallNottinghamNottinghamshireNG15 7SZMsElaineEast
4572Frannock Manor PLCClywedog RoadNorth Wrexham Industrial EstateWrexhamClwydLL13 9XNMrFrederickFranklin
4573Gimley of Gosborton LtdLong Leys RoadLincolnLincolnshirePE11 4NLMrGeorgeGimley
4574Hamshaw LtdWhitby AvenueIngolPrestonLancashirePR2 3GAMissHannahHamshaw
4575Immingham SuppliesLancaster ApproachNorth KillingholmeImminghamNorth East LincolnshireDN40 3JZMrsIreneIngols
4576Jedson Manufacturing LtdBeacon RoadTrafford ParkManchesterGreater ManchesterM17 1AFMrJamieJedson
4577Kimbolton Carriers LtdThrapston RoadKimboltonHuntingdonHuntingdonshirePE28 0HWMrKenKendrick
4578Lemmy's Wines and Spirits LtdStation RoadSwinesheadBostonLincolnshirePE20 3PNMrLiamLee
4579Mulgroon's Balloons LtdSpidlington RoadFaldingworthMarket RasenLincolnshireLN8 3SQMissMirandaMulgroon
4580Norma's Cakes LtdAmington RoadYardleyBirminghamWest MidlandsB25 8ETMrsNormaNixon
4581Oswald Furnishings LtdDiamond AvenueKirkby-in-AshfieldNottinghamNottinghamshireNG17 7GRMrOliverOswald
4582Peacock & Bradshaw LtdPeterly RoadCowleyOxfordOxfordshireOX4 2TYMrPeterPeacock
4583Quentin's Cabins LtdWalton New RoadBruntingthorpeLutterworthLeicestershireLE17 5RDMrQuentinQuinn
4584Rena's Supplies LtdWigan RoadEuxtonChorleyLancashirePR7 6JJMrsRenaRimshaw
4585Shenley Shovels LtdHarper LaneShenleyRadlettHertfordshireWD7 9HEMrSimonSixsmith
4586Tyneside Machines LtdSycamore StreetWallsendNorth TynesideTyne and WearNE31 1AXMrTimTimpkins
4587United Uniforms LtdLongley RoadMedway City EstateRochesterKentME2 4DUMsUnaUnsworth
4588Venga Coverings LtdCholmley WayEskdale Industrial EstateWhitbyNorth YorkshireYO22 4NJMrVinnieVenga
4589Wilton's Fine Products LtdKey Business ParkKingsbury RoadBirminghamWest MidlandsB24 9PTMrWillWilton
4590Xavier Coast to Coast LtdMarchwood Industrial EstateNormandy WaySouthamptonHampshireSO40 4PBMrsXenaXavier
4591Yaxley Pies LtdStation RoadBroadwayYaxleyHuntingdonshirePE7 3ENMissYasmineYolander
4592Zimmerman's of Sawtry LtdBrookside Industrial EstateSawtryHuntingdonHuntingdonshirePE28 5SBMrZakZanetti
4593Ambletons PLCUnit 15 Ballon Wood Ind EstCoventry LaneNottinghamNottinghamshireNG9 3GJMrArnoldAmbleton
4594Beckley Banners LtdUnit 77 Regal WorksJohns Road, KirkdaleLiverpoolMerseysideL20 8PRMrBertieBeckley
4595Cedric Collier LtdUnit 98 Bergen WaySouthfields Industrial EstateHullEast YorkshireHU7 0YQMrCedricCollier
4596Duke Demolition Ltd762 Edinburgh RoadNewhouseMotherwellNorth LanarkshireML1 5SYMrDerekDuke
4597Emmerson Enterprises LtdUnit 72 Ely Distribution CentreArgyle WayCardiffSouth GlamorganCF5 5NJMrEddieEmmerson
4598Fentham Farms LtdSopwith DriveBrooklands Industrial ParkWeybridgeSurreyKT13 0UZMissFionaFinley
4599Gurnock Garage LtdGreen LaneColtishallNorwichNorfolkNR12 7AJMrGarryGumton
4600Henry Hammerton LtdYellowfield Lane, SpringfieldColtonUlverstonCumbriaLA12 8HEMrHenryHammerton
4601Irlington Industries LtdPlot 22 Pexton RoadKellythorpeDriffieldEast YorkshireYO25 9DJMrIanIcke
4602Jeff Johnston LtdKnightons LaneDunsfoldGodalmingSurreyGU8 4NYMrJeffJohnston
4603Kensome & Kingston LtdStafford RoadKnightlyStaffordWest MidlandsST20 0JRMrsKarenKensome
4604Local Landmarks LtdKendall Business ParkApplebyKendallCumbriaLA9 6EWMrsLenaLilly
4605Motorman LtdUnit 92 Shorten Brook WayAltham Business ParkAccringtonLancashireBB5 5YJMrMatthewMarsh
4606Noreen Nightingale LtdGatehead RoadCrosshouseKilmarnockEast AyrshireKA2 0HPMsNoreenNightingale
4607Oakham Optometrists Ltd52 Station RoadUppinghamOakhamRutlandLE15 9TZMrOrvilleOwen
4608Purvis & Purvis Ltd92 Beech StreetPadihamBurnleyLancashireBB12 7EEMrPaulPurvis
4609Quakerman's Quills LtdUnit 52 Ormidale SquareTiverton Business ParkTivertonDevonEX16 6TWMrQuincyQuant
4610Renley of Roehampton LtdUnit 72 Aston Fields Ind EstateAston RoadBromsgroveWorcestershireB60 3EXMrRogerRenley
4611Sally's Supplies Ltd57 Camford WaySundon ParkLutonBedfordshireLU3 3ANMrsSallySmithers
4612Thompson's Tents LtdHovefields AvenueBurnt MillsBasildonEssexSS13 1EBMrTobyThompson
4613Ursula Umbridge LtdNortholt RoadLondon Heathrow AirportHounslowGreater LondonTW6 2JAMrsUrsulaUmbridge
4614Violet Vans LtdDaneshill East Industrial EstateBell RoadBasingstokeHampshireRG24 8PXMrsVioletVardy
4615Williams of Walsham LtdJade House FarmKnaptonNorth WalshamNorfolkNR28 0RXMrWayneWilliams
4616X-cel LtdWindsor Trading EstateDownhamBillericayEssexCM11 1QEMrsXariaXanda
4617Yeovil Yards LtdUnit 99 Abbey Trading EstateStourton WayYeovilSomersetBA21 3ARMrYusefYorke
4618Zen Products LtdEuropa WayLune Industrial EstateLancasterLancashireLA1 5QPMrZaneZellweger


Here are the cust_id and cust_name fields along with the remaining fields from the Customer table, ordered by the cutomer ID.


Again, the SQL query for MySQL and T-SQL to produce the data is the same and as follows:

MySQL Code and T-SQL Code (MS SQL)

SELECT cust_id, cust_name, cust_mobile, cust_email,
cust_email_opt_out, cust_thirdparty
FROM exc_customer
ORDER BY cust_id ASC
cust_idcust_namecust_mobilecust_emailcust_email_opt_outcust_thirdparty
4567Acorn Traders Ltd07570 667889atraders@hotmailtest.com00
4568Billingham's of Braithwaite Ltd07579 567567bertie@billinghamstest.co.uk00
4569Colcon Ltd07978 444333colcon@gmailtest.com00
4570Dimbleby PLC07976 444323dimblebyplc@talktalktest.co.uk00
4571East Empire Ltd07571 443667sales@eastempiretest.com00
4572Frannock Manor PLC07578 222111fred@frannockstest.com00
4573Gimley of Gosborton Ltd07579 876543georgegimley@aoltest.com00
4574Hamshaw Ltd07979 987876hh@hamshawltdtest.com00
4575Immingham Supplies07979 787676iingols@gmailtest.com00
4576Jedson Manufacturing Ltd07572 653489jamiej@jedsonstest.com00
4577Kimbolton Carriers Ltd07878 676767kkendrick@kimboltoncarrierstest.co.uk00
4578Lemmy's Wines and Spirits Ltd07570 232767llee@lemmystest.com00
4579Mulgroon's Balloons Ltd07978 212343miranda@mulgroonstest.co.uk00
4580Norma's Cakes Ltd07578 675465nnixon@normascakestest.com00
4581Oswald Furnishings Ltd07579 765476osfurnishings@yahootest.co.uk00
4582Peacock & Bradshaw Ltd07576 775655peterp@hotmailtest.com01
4583Quentin's Cabins Ltd07978 743432qquinn@talktalktest.co.uk00
4584Rena's Supplies Ltd07976 555444rrimshaw@renastest.com11
4585Shenley Shovels Ltd07571 676754simon.sixsmith@shenleysshovelstest.co.uk00
4586Tyneside Machines Ltd07667 898989t.timpkins@tmltdtest.co.uk00
4587United Uniforms Ltd07976 443344uunsworth@aoltest.com01
4588Venga Coverings Ltd07976 567654vinnie.venga@yahootest.co.uk00
4589Wilton's Fine Products Ltd07571 656565will@wiltonstest.com01
4590Xavier Coast to Coast Ltd07578 555664xena@xavierctoctest.com00
4591Yaxley Pies Ltd07579 643987yasmine@yaxleypiestest.co.uk01
4592Zimmerman's of Sawtry Ltd07573 458792zakzanetti@hotmailtest.com00
4593Ambletons PLC07572 643324aa@hotmailtest.com10
4594Beckley Banners Ltd07573 650909bb@beckleytest.com00
4595Cedric Collier Ltd07574 888976cedric@collierstest.com00
4596Duke Demolition Ltd07574 775544theboss@dukestest.co.uk00
4597Emmerson Enterprises Ltd07978 978676eddie@emmersonstest.com00
4598Fentham Farms Ltd07978 423332ff@fenthamfarmstest.net00
4599Gurnock Garage Ltd07978 455455gary@gurnockstest.com00
4600Henry Hammerton Ltd07977 669898henry@hammertontest.co.uk00
4601Irlington Industries Ltd07978 195743ii@irlingtonltdtest.com11
4602Jeff Johnston Ltd07978 923245mrjohnston@johnstontest.com00
4603Kensome & Kingston Ltd07978 499188kk@kandktest.com00
4604Local Landmarks Ltd07978 399993lenalilly@locallandmarkstest.com00
4605Motorman Ltd07977 911233matt@motormantest.com11
4606Noreen Nightingale Ltd07977 288881nn@noreennightingaletest.com00
4607Oakham Optometrists Ltd07987 779933orville@oakham-optometriststest.com00
4608Purvis & Purvis Ltd07978 831765pp@purvisandpurvistest.com00
4609Quakerman's Quills Ltd07978 498004quincy@quakermanstest.com00
4610Renley of Roehampton Ltd07978 755000roger@renleystest.com00
4611Sally's Supplies Ltd07571 726678sally@smitherstest.com00
4612Thompson's Tents Ltd07646 449988tthompson@hotmailtest.com00
4613Ursula Umbridge Ltd07978 545480sales@umbridgetest.com00
4614Violet Vans Ltd07578 449988vv@violetvanstest.net00
4615Williams of Walsham Ltd07676 693214wayne@wwtest.co.uk00
4616X-cel Ltd07678 778881xx@xceltest.com00
4617Yeovil Yards Ltd07978 654765yusef@yeovilyardstest.com00
4618Zen Products Ltd07978 776634zane@zenstest.com00


Listing the staff table

The next set of data is from a simple query listing all fields from the Staff table, ordering the results by Staff ID number.

Both the SQL query for MySQL and T-SQL to produce the data is the same:

MySQL Code and T-SQL Code (MS SQL)

SELECT staff_id, staff_mobile, staff_add1, staff_add2,
staff_add3, staff_county, staff_postcode,
staff_salutation, staff_firstname,
staff_surname, staff_email
FROM exc_staff
ORDER BY staff_id ASC
staff_idstaff_mobilestaff_add1staff_add2staff_add3staff_countystaff_postcodestaff_salutationstaff_firstnamestaff_surnamestaff_email
5007575 7575721 High StreetBigthorpeAldershotHampshireGU11 5TYMrsAntheaAllena.allen@widge-it.com
5107575 7575732 Acacia AvenueSmallthorpeBrightonEast SussexBN42 5YTMrBillyBeaumontb.beaumont@widge-it.com
5207575 7575743 North BankMidthorpeCirencesterGloucestershireGL7 5YYMrCharlesChuzzlewitc.chuzzlewit@widge-it.com
5307575 7575754 East StreetUpthorpeDidcotOxfordshireOX11 5TYMissDeirdrieDawsond.dawson@widge-it.com
5407575 7575765 West RoadDownthorpeEnderbyLeicestershireLE19 5YYMrErnieEcclestonee.ecclestone@widge-it.com
5507575 7575776 South ViewMidsideFileyYorkshireYO14 5TYMrsFrancescaFavershamf.faversham@widge-it.com
5607575 7575787 Lower BankNearsideGuildfordSurreyGU3 5YTMissGinaGinolag.ginola@widge-it.com
5707575 7575798 Upper LaneRightsideHartlepoolCounty DurhamTS25 5YYMrHarryHarrisonh.harrison@widge-it.com


Listing the transactions table

To produce the required output data from the Transactions table and order the results by Transaction ID number we can use the following queries.

Note that MySQL and T-SQL use different syntax to format the output of UK dates:

MySQL Code

SELECT trans_id, trans_staff_id, trans_cust_id,
DATE_FORMAT(trans_date, '%d/%m/%Y') AS trans_date,
trans_grn_widgets_sold, trans_blu_widgets_sold,
trans_grn_widgets_sales, trans_blu_widgets_sales,
trans_ins_sales FROM exc_transactions
ORDER BY trans_id ASC
T-SQL Code (MS SQL)

SELECT trans_id, trans_staff_id, trans_cust_id,
CONVERT (varchar(10), trans_date, 103) AS trans_date,
trans_grn_widgets_sold, trans_blu_widgets_sold,
trans_grn_widgets_sales, trans_blu_widgets_sales,
trans_ins_sales FROM exc_transactions
ORDER BY trans_id ASC
trans_idtrans_staff_idtrans_cust_idtrans_datetrans_grn_widgets_soldtrans_blu_widgets_soldtrans_grn_widgets_salestrans_blu_widgets_salestrans_ins_sales
5250458903/01/201710500.000.000.00
5351458303/01/201713500.001800.00100.00
5452456804/01/2017201000.000.00100.00
5553457004/01/2017482000.004500.000.00
5655458205/01/2017552500.003000.00100.00
5756458205/01/2017231000.001800.000.00
5850458709/01/2017311500.00600.000.00
5951458909/01/2017311500.00600.00100.00
6052458210/01/2017412000.00600.00100.00
6153456811/01/2017412000.00600.00100.00
6255456812/01/2017321500.001200.00100.00
6351461812/01/2017201000.000.000.00
6456456713/01/2017723500.001200.00100.00
6550458316/01/2017361500.003600.000.00
6651458416/01/2017271000.004000.00200.00
6752458318/01/2017512500.00600.000.00
6853458520/01/2017663000.003500.00100.00
6955461620/01/2017452000.003000.00100.00
7056461720/01/2017663000.003600.000.00
7150461825/01/2017331500.001800.000.00
7251458725/01/2017241000.002400.000.00
7352458925/01/2017723300.001200.000.00
7451456725/01/2017021200.000.000.00
7553457025/01/2017311500.00600.000.00
7652457130/01/2017613000.00600.000.00
7753457230/01/2017402000.000.000.00
7855457330/01/2017623000.001200.000.00
7950458506/02/2017231000.001800.000.00
8051458207/02/2017341500.002400.000.00
8151461807/02/2017251000.003000.000.00
8252460107/02/2017351500.003000.000.00
8353460207/02/2017221000.001200.000.00
8454460307/02/2017351500.003000.000.00
8555461607/02/2017422000.001200.000.00
8656458207/02/201714500.002400.000.00
8757458308/02/201716500.003600.000.00
8850461613/02/2017512500.00600.000.00
8951457213/02/2017512500.00600.000.00
9051457013/02/2017412000.00600.000.00
9152458513/02/2017442000.002400.00200.00
9253461713/02/2017351500.003000.000.00
9354456715/02/2017371500.004200.000.00
9455457115/02/2017331500.001800.000.00
9556457215/02/2017331500.001800.000.00
9657459115/02/2017241000.002400.000.00
9757459216/02/2017281000.004800.00200.00
9850461820/02/2017462000.003400.000.00
9951460120/02/2017361500.003550.000.00
10052460220/02/2017351500.003000.000.00
10152460320/02/2017351500.003000.000.00
10253458320/02/2017341500.002400.000.00
10354458523/02/2017442000.002400.000.00
10455461723/02/2017442000.002400.000.00
10556461623/02/2017542500.002400.000.00
10657457124/02/2017562500.003600.000.00
10750461128/02/2017361500.003600.000.00
10851461228/02/2017361500.003600.000.00
10952461328/02/2017361500.003600.000.00
11052460328/02/2017331500.001800.000.00
11153461602/03/2017432000.001800.000.00
11254461403/03/2017432000.001800.000.00
11355457203/03/2017331500.001800.000.00
11456460303/03/2017331500.001800.000.00
11557457103/03/2017331500.001800.000.00
11656460107/03/2017251000.003000.00100.00
11757460208/03/2017251000.003000.000.00
11855460309/03/2017251000.003000.00100.00
11954458309/03/2017241000.002400.000.00
12054458509/03/2017341500.002400.000.00
12153461210/03/2017331500.001800.000.00
12252461610/03/2017331500.001800.000.00
12350461710/03/2017331500.001800.000.00


Click the button below to advance to the next stage


Next: >> Building Date Formats


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