This is not a test to see if a record exists before selecting it, or vice versa.
The problem is that I have a database with many records, they are stored by date, by day, to be specific, every day should have a set of values, but some days may not have any values at all, they may not exist. Therefore, when I try to execute a query, I need to show all the data, even if it does not technically exist, it can be displayed at least as an empty space, but it should be displayed.
Think about this table:
___________________________________
| id | date | value1 | value2 |
| 1 | 02/01/2014 | 1 | 1 |
| 2 | 02/03/2014 | 2 | 2 |
| 3 | 02/04/2014 | 3 | 3 |
| 4 | 02/06/2014 | 4 | 4 |
Now, what needs to be done is to return all data between a certain date range, for example, from 02/01/2014to 02/03/2014, it should return all values between this date range, for example:
SELECT * FROM myTable WHERE date>=`02/01/2014` AND date<=`02/03/2014`
But this will only return this:
___________________________________
| id | date | value1 | value2 |
| 1 | 02/01/2014 | 1 | 1 |
| 2 | 02/03/2014 | 2 | 2 |
Now I know that this is pretty obvious, it selects all the data that exists in the table, given the range that I sent to the request, but I work with a report that does not care whether there were values for this given day or not, it must return every day, even if there were records for that day or not, which means that even if 02/02/2014it is not in the table, it must also be returned.
Example:
___________________________________
| id | date | value1 | value2 |
| 1 | 02/01/2014 | 1 | 1 |
| | 02/02/2014 | | |
| 2 | 02/03/2014 | 2 | 2 |
It does not matter that he has no data, he simply can not leave the day, as if this did not happen.
COALESCE ISNULL, , , Null - .
- ?