Using SQL Server 2000
Having Two Tables
Table1
Date ID
20090101 001
20090102 001
….
20090101 002
20090102 002
…
20090101 003
20090102 003
…
So on..,
Table2
ID Name Date
001 Raja 20090408
001 Raja 20090502
001 Raja 20090503
002 Ravi 20090312
002 Ravi 20090522
003 Saga 20090802
003 Saga 20091022
So on..,
Query
SELECT
Table1.Date, Table1.ID,
Table2.Name, Table2.Date
FROM table1
INNER JOIN table2 ON table1.id = table2.id
ORDER BY table1.id, table1.date
Output
Date ID Name Table2.Date
20090101 001 Raja 20090408
20090101 001 Raja 20090502
20090101 001 Raja 20090503
20090102 001 Raja 20090408
20090102 001 Raja 20090502
20090102 001 Raja 20090503
…
20090101 002 Ravi 20090312
20090101 002 Ravi 20090522
20090102 002 Ravi 20090312
20090102 002 Ravi 20090522
…
So on…,
Why am getting a table1.date again and again. I want to display like this.
Expected Output
Date ID Name Table2.Date
20090101 001 Raja -
…
20090502 001 Raja 20090502
20090503 001 Raja 20090503
…
20090107 001 Raja -
20090108 001 Raja 20090408
….
So on…,
I put "–" instead of Null Column
Table2.Date should equal to Table1.Date, means
Table1.Date, Table1.ID should display all the columns,
Table2.Date should display with Table1.Date Related column.
Example.
Table2 Column Values are
Date - 20090203, 20090205...,
Table1.ID Table1.Date Table2.Date
001 20090201
001 20090202
001 20090203 20090203
001 20090204
001 20090205 20090205
001 20090206
...,
Before I make a query in Access 2003
SELECT AllPossibleCardEvents.Id, AllPossibleCardEvents.Date, Actual.Date AS Table2Date FROM ((SELECT p.Id, AllDates.Date FROM (SELECT DISTINCT Date FROM table2) AllDates, table1 p) AllPossibleCardEvents LEFT OUTER JOIN table2 Actual ON AllPossibleCardEvents.Id = Actual.Id AND AllPossibleCardEvents.tDate = Actual.Date) )
Now the above query is working perfectly for my expected output in access
How to make a Sql query for this condition?
Need Query Help