C
cjg.groups
Hello, I am trying to get the effect of a LEFT JOIN, but my method
seems unnecessarily complex. Please help if there is a better way to
do this.
The effect I need, from Access help, is:
"Left outer joins include all of the records from the first (left) of
two tables, even if there are no matching values for records in the
second (right) table."
The data looks like:
ID Value YrHr
1 200 Year
1 300 Year
2 20 Hour
6 400 Year
6 10 Hour
6 20 Hour
The Value field was overloaded so YrHr indicates what type of data it
contains. Bad, I know.
The query must split Years and Hours into different fields. It will
also SUM all Values with the same ID. But, data in the displayed
fields must line up horizontally with the ID.
The end result should look like:
ID Year Hr
1 500
2 20
6 400 30
ID 1 does not have data for Month, so a blank space is left in that
cell.
Currently, I am using LEFT JOIN on nested SQL queries, each with their
own similar-but-different WHERE clause. The ID list is the left most
query in the JOIN. ie:
SELECT DISTINCT table.ID, tmp1.Year, tmp2.Hour
FROM table LEFT JOIN
[SELECT SUM(Value) As Year FROM table WHERE YrHr = "Year" AND
<conditionals> GROUP BY ID]. AS tmp1 ON table.ID = tmp1.ID
WHERE <conditionals>;
The above actually contains another join to create the Hour field, but
it would muddy my example and I haven't even created it yet.
Is there a way to not use complete nested SQL statements, but simply
apply the "WHERE YrHr" conditional to each field in a SELECT
statement? Is there a better way to do this? Thank you.
seems unnecessarily complex. Please help if there is a better way to
do this.
The effect I need, from Access help, is:
"Left outer joins include all of the records from the first (left) of
two tables, even if there are no matching values for records in the
second (right) table."
The data looks like:
ID Value YrHr
1 200 Year
1 300 Year
2 20 Hour
6 400 Year
6 10 Hour
6 20 Hour
The Value field was overloaded so YrHr indicates what type of data it
contains. Bad, I know.
The query must split Years and Hours into different fields. It will
also SUM all Values with the same ID. But, data in the displayed
fields must line up horizontally with the ID.
The end result should look like:
ID Year Hr
1 500
2 20
6 400 30
ID 1 does not have data for Month, so a blank space is left in that
cell.
Currently, I am using LEFT JOIN on nested SQL queries, each with their
own similar-but-different WHERE clause. The ID list is the left most
query in the JOIN. ie:
SELECT DISTINCT table.ID, tmp1.Year, tmp2.Hour
FROM table LEFT JOIN
[SELECT SUM(Value) As Year FROM table WHERE YrHr = "Year" AND
<conditionals> GROUP BY ID]. AS tmp1 ON table.ID = tmp1.ID
WHERE <conditionals>;
The above actually contains another join to create the Hour field, but
it would muddy my example and I haven't even created it yet.
Is there a way to not use complete nested SQL statements, but simply
apply the "WHERE YrHr" conditional to each field in a SELECT
statement? Is there a better way to do this? Thank you.