New Posts  All Forums:Forum Nav:

SQL Joins - Page 2

post #11 of 15
Agreed that this is more of a presentation issue. There isn't enough information to suggest a better way of doing it anyway. Will only one workout ever be retrieved at a time, or will you sometimes want 100 of them? If the former, then the easiest thing to do is print the workout details from the first record returned and then loop through the records printing out the exercise details. If the latter, this would require a bit more logic to do correctly, probably along the lines of what Plan9 mentioned above. You could do the UNION but you'll need to have logic to pry the results apart anyway (or make the query for each workout which will be horribly slow), so you'll just be making a slower query with no added benefit.
Edited by randomizer - 7/4/13 at 3:05am
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
post #12 of 15
Thread Starter 
I just ended up doing 2 queries. One to get the workout name and description then a second query to get all the exercises for the workout.
My System
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 @ Stock Asus P6T ATI HD5870 OCZ 6GB 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Samsung 840 Evo Caviar Black 640GB LG DVD Drive Cm Hyper 212+ 
CoolingOSMonitorPower
Arctic Cooling Accelero Twin Turbo II Windows 7 64bit ASUS VW246H Corsair HX850 
Case
CM 690 II Adavanced 
  hide details  
Reply
My System
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 @ Stock Asus P6T ATI HD5870 OCZ 6GB 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Samsung 840 Evo Caviar Black 640GB LG DVD Drive Cm Hyper 212+ 
CoolingOSMonitorPower
Arctic Cooling Accelero Twin Turbo II Windows 7 64bit ASUS VW246H Corsair HX850 
Case
CM 690 II Adavanced 
  hide details  
Reply
post #13 of 15
Quote:
Originally Posted by the_dude View Post

I just ended up doing 2 queries. One to get the workout name and description then a second query to get all the exercises for the workout.

I'm guessing this is for a smaller scale project?

If you were to build an online portal which could potentially heavy load, but then you'd need to revert back to your former query and structure the output in server side code (eg PHP). The reason is because running two SQL requests like that carries more overhead than running one query and selectively displaying the data you want from it.

However I only post this as informational in case this project expands and you're finding yourself looking for ways to optimize your routines. As what you've got is working, there's no point in changing that. smile.gif
post #14 of 15
Thread Starter 
Quote:
Originally Posted by Plan9 View Post

I'm guessing this is for a smaller scale project?

If you were to build an online portal which could potentially heavy load, but then you'd need to revert back to your former query and structure the output in server side code (eg PHP). The reason is because running two SQL requests like that carries more overhead than running one query and selectively displaying the data you want from it.

However I only post this as informational in case this project expands and you're finding yourself looking for ways to optimize your routines. As what you've got is working, there's no point in changing that. smile.gif

Yea the join I had originally got me the information I was looking for. The problem was that if I wanted to print out the workout name and description only once I would have to go into the array manually which wouldn't work if I had no exercises.

This is only a small little project for myself anyways, just for some practice.
My System
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 @ Stock Asus P6T ATI HD5870 OCZ 6GB 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Samsung 840 Evo Caviar Black 640GB LG DVD Drive Cm Hyper 212+ 
CoolingOSMonitorPower
Arctic Cooling Accelero Twin Turbo II Windows 7 64bit ASUS VW246H Corsair HX850 
Case
CM 690 II Adavanced 
  hide details  
Reply
My System
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 @ Stock Asus P6T ATI HD5870 OCZ 6GB 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Samsung 840 Evo Caviar Black 640GB LG DVD Drive Cm Hyper 212+ 
CoolingOSMonitorPower
Arctic Cooling Accelero Twin Turbo II Windows 7 64bit ASUS VW246H Corsair HX850 
Case
CM 690 II Adavanced 
  hide details  
Reply
post #15 of 15
Quote:
Originally Posted by the_dude View Post

The problem was that if I wanted to print out the workout name and description only once I would have to go into the array manually which wouldn't work if I had no exercises.

Obviously you'd check the size of the array before trying to iterate through it using an index. Although if you can use a foreach loop this isn't needed.
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding