Quantcast
Channel: User Oswald - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Answer by Oswald for Include a complex logic in a single MySQL Query

$
0
0

Use a self join:

SELECT r1.HOTEL_ID, r1.MAX_ADULTS, r1.NO_OF_ROOMS,    r2.MAX_ADULTS, r2.NO_OF_ROOMS,    r3.MAX_ADULTS, r3.NO_OF_ROOMS,FROM rooms AS r1INNER JOIN rooms AS r2 ON r1.HOTEL_ID=r2.HOTEL_IDINNER JOIN rooms AS r3 ON r1.HOTEL_ID=r3.HOTEL_IDWHERE r1.MAX_ADULTS=1AND r2.MAX_ADULTS=2AND r3.MAX_ADULTS=3

You will have to add clauses to check the input number of rooms conditions.

The generated result_id would be r1.HOTEL_ID.

You would get a single row per hotel.


Viewing all articles
Browse latest Browse all 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>