shakespeare5677
Programmer
Hi,
I'm working with MySQL and here's the problem:
I have two tables: RecordTable and DetailTable. The important fields in Record table are ID, Date, Time, Deleted; and the DetailTable consists of ID, RecordID, Number, Class, Details and Deleted.
I was able to produce a nice little list where within each time period and date, I had a group of details per record with the data records (fake id=1) first and 2 fake records (fake ids=2 and 3) at the end:
time
->date
-->record
---->1
---->1
---->1
---->2
---->3
-->record
---->1
---->1
---->1
---->2
---->3
and so on
by using a fake table filled with data like this
1,0
2,0
3,0
and the following query
The problem is that now the boss wants all detail classes to be included, not just one and I still need the records to come in the same order as before (because those fake records are used for strange calculations in the report), now belonging to their class groups:
class
-->time
---->date
------>record
-------->1
-------->1
-------->1
-------->2
-------->3
------>record
-------->1
-------->1
-------->1
-------->2
-------->3
I need to change the query but I'm all out of ideas. Please help.
-Max
I'm working with MySQL and here's the problem:
I have two tables: RecordTable and DetailTable. The important fields in Record table are ID, Date, Time, Deleted; and the DetailTable consists of ID, RecordID, Number, Class, Details and Deleted.
I was able to produce a nice little list where within each time period and date, I had a group of details per record with the data records (fake id=1) first and 2 fake records (fake ids=2 and 3) at the end:
time
->date
-->record
---->1
---->1
---->1
---->2
---->3
-->record
---->1
---->1
---->1
---->2
---->3
and so on
by using a fake table filled with data like this
1,0
2,0
3,0
and the following query
Code:
SELECT RecordTable.Date, RecordTable.Time,
DetailTable.Class, DetailTable.Detail,
FakeTable.ID
FROM (RecordTable INNER JOIN DetailTable
ON RecordTable.ID = DetailTable.RecordID)
LEFT JOIN FakeTable
ON RecordTable.Deleted = FakeTable.Field2
WHERE ((FakeTable.ID=SOME_ID
AND DetailTable.Class=SOME_CLASS)
OR (RecordTable.Deleted=0
AND DetailTable.Number=1
AND FakeTable.ID IN (2,3)))
AND rundownitem.deleted=0
ORDER BY RecordTable.Time,
RecordTable.Date, FakeTable.ID;
The problem is that now the boss wants all detail classes to be included, not just one and I still need the records to come in the same order as before (because those fake records are used for strange calculations in the report), now belonging to their class groups:
class
-->time
---->date
------>record
-------->1
-------->1
-------->1
-------->2
-------->3
------>record
-------->1
-------->1
-------->1
-------->2
-------->3
I need to change the query but I'm all out of ideas. Please help.
-Max