Form my two tables, I want to select SUB_Limit and count the number of rooms (only the active one).
So the query should returns me something like this:
|-----------|------------|-------------|
| SUB_Limit | ROO_Number | ROO_HotelId |
|-----------|------------|-------------|
| 10 | 0 | 1 |
| 15 | 3 | 2 |
| 5 | 2 | 3 |
| 25 | 0 | 4 |
|-----------|------------|-------------|
Why this query do not return me the desired output please ?
SELECT
ROO_HotelId,
SUB_Limit,
COUNT(ROO_Id) AS ROO_Number
FROM ___Rooms
LEFT JOIN ___Subscriptions
ON ___Rooms.ROO_HotelId = ___Subscriptions.SUB_HotelId
WHERE ROO_Status = 'active'
AND SUB_HotelId = 1
AND ROO_HotelId = 1
Actually, it gave me:
|-----------|------------|
| SUB_Limit | ROO_Number |
|-----------|------------|
| 15 | 3 |
| 5 | 2 |
|-----------|------------|
So I haven't the ___Subscriptions with no rooms.
Here the SQL Fiddle for help.
Thanks in advance.
Subscriptions LEFT JOIN Rooms(not the same asRooms RIGHT JOIN Subscriptions) and handle the case when the rightmost side of the join returns null via code. That's how I'd do it