BARNI
BARNI

Reputation: 142

Combine 2 Mysql queries into one

i have two queries

1)

 SELECT COUNT(room_id) FROM room WHERE hotel_id LIKE '777' GROUP BY room_id

2)

SELECT COUNT(room_id) FROM orders WHERE hotel_id LIKE '777' AND checkout = '$today'

I want to know, if i can create a single query which will return both value. I tried JOIN but, can not get a wanted result. (Do not know about JOIN s)

Upvotes: 0

Views: 42

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

I suspect the query you want is:

SELECT COUNT(*) as NumRooms, SUM(checkout = '$today') as NumCheckoutToday
FROM orders
WHERE hotel_id LIKE '777' ; 

Your first query is going to return a list of "1"s for every room in the hotel. That doesn't seem particularly useful. I'm guessing you want the actual count.

Upvotes: 1

Related Questions