I can't find a solution to the following problem. Assuming I have 2 tables:
Table 1:
Name | Age
Nick | 52
Adam | 52
Monica | 40
Table 2:
Name | Task | Value | Done
Nick | Clean | 010000 | Y
Nick | | 011000 |
Nick | | 020000 |
Nick | Vacuum | 025000 |
Nick | Do Dishes | 030000 |
Adam | | 010000 |
Adam | Clean | 015000 | Y
Adam | Dust | 030000 | Y
Adam | Cook | 035000 |
Monica | PaintHouse | 010000 |
Monica | Garbage | 020000 |
What I'm looking for is this:
How can I write an SQL that gives me the result of all everyone that is 52 and shows the next task he/she has to do, skipping all the empty entries in "task" Output should look something like:
Name | Age | Task
Nick | 52 | Vacuum
Adam | 52 | Cook
Database is 2000 version of MS SQL Server. Also, I don't have any write access, only read access.
UPDATE: In the original post, I posted:
Adam | Cook | 030000
This was not correct It should have been:
Adam | Cook | 035000
I have corrected this error.
select * from #Tasks inner join #Names on #Tasks.name = #Names.name where #Names.age = 52 and #Tasks.task != ''
thats as close as you'll get but then because you lack an autoinc key orDateAdded
sort of timestamp its just not possible to accurately determine what was the last Task performed.