Hi,
As you guessed I’m new to PHP and I’m looking for some guidance on an SELECT command.
I have two tables (table1 = full names, DoB etc) and (table2 = full names, swim times, improvements, Medals etc). I would like to be able to run an SELECT command which will list all the people in Table1 and display columns next to them with data extracted from Table2.
i.e. t1.First Name, t1.Surname, t1.Aged, t2.PBs, t2.Medals
I have used the following SELECT to create my list from Table1
SELECT
t1.ChristianName AS "First Name",
t1.Surname AS Surname,
YEAR(DATE_SUB(NOW(), INTERVAL TO_DAYS(t1.DateofBirth) DAY)) AS Aged
FROM table1 t1
ORDER BY t1.Gender, t1.DateofBirth Desc, t1.Surname
And I have the following separate SELECT which gives me the results from Table2 which I need.
SELECT COUNT(*) FROM table2 t2 WHERE t2.Date BETWEEN "2011-09-01" and "2012-08-31" AND t2.Improvement >0 AS PBs;
AND
SELECT COUNT(*) FROM table2 t2 WHERE t2.Position BETWEEN "2011-09-01" and "2012-08-31" BETWEEN "1" and "3" AS Medals;
What I would like to be able to do is list the t2.improvement COUNT() and the t2.psotition COUNT() against each Line in Table1 which are for that particular person so the result would like similar to the below.
[table]
[tr]
[td]First Name[/td]
[td]Surname[/td]
[td]Aged[/td]
[td]PBs[/td]
[td]Medals[/td]
[/tr]
[tr]
[td]Clare[/td]
[td]Owen[/td]
[td]12[/td]
[td]32[/td]
[td]16[/td]
[/tr]
[tr]
[td]Joe[/td]
[td]Bloggs[/td]
[td]17[/td]
[td]15[/td]
[td]3[/td]
[/tr]
[tr]
[td]Bill[/td]
[td]Gates[/td]
[td]18[/td]
[td]10[/td]
[td]1[/td]
[/tr]
[/table]
Can this be done in a SELECT query?
I have a common link between each table which is [tt]T*.swim_id[/tt] if that helps!
I’ve tried UNIONS and JOINS but I’m getting mixed up with these and instead of the table listing the results for the individual person, it just lists the full results against everyone name! (see below)
[table]
[tr]
[td]First Name[/td]
[td]Surname[/td]
[td]Aged[/td]
[td]PBs[/td]
[td]Medals[/td]
[/tr]
[tr]
[td]Clare[/td]
[td]Owen[/td]
[td]12[/td]
[td]57[/td]
[td]20[/td]
[/tr]
[tr]
[td]Joe[/td]
[td]Bloggs[/td]
[td]17[/td]
[td]57[/td]
[td]20[/td]
[/tr]
[tr]
[td]Bill[/td]
[td]Gates[/td]
[td]18[/td]
[td]57[/td]
[td]20[/td]
[/tr]
[/table]
Any and all help or guidance greatly appreciated.