Welcome Guest, Not a member yet? Register   Sign In
Help writing a SQL subquery
#1

[eluser]theshiftexchange[/eluser]
Hey guys,

I know this needs to be a SQL subquery - but after looking/googling/trying I cant work out the logical answer to this "seemingly" simple subquery.

Table A has a list of overtime worked by users
Table B is a list of users

I need the total overtime worked by each user (first SQL statement below) included in the user list I'm generating (second SQL statement)

Table A
Code:
SELECT SUM(`shift_length`) AS shift_length FROM (`overtime_assigned`)
WHERE `user_ID` = '.$user_ID

Table B
Code:
SELECT * FROM (`overtime_list`)
JOIN `users` ON `users`.`user_ID` = `overtime_list`.`user_ID`
JOIN `stations` ON `users`.`station_ID` = `stations`.`station_ID`
JOIN `postcode_db` ON `users`.`postcode_ID` = `postcode_db`.`postcode_ID`
WHERE `date` = '.$date.' AND `type` = '.$type.' AND `day` = '.$day.'
GROUP BY `postcode_db`.`postcode_ID`

Anyone able to help shed light on this? Thanks in advance.


Messages In This Thread
Help writing a SQL subquery - by El Forum - 04-07-2010, 08:45 AM
Help writing a SQL subquery - by El Forum - 04-07-2010, 09:01 AM
Help writing a SQL subquery - by El Forum - 04-07-2010, 09:45 AM
Help writing a SQL subquery - by El Forum - 04-07-2010, 09:57 AM
Help writing a SQL subquery - by El Forum - 04-07-2010, 10:12 AM
Help writing a SQL subquery - by El Forum - 04-07-2010, 05:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB