user11131551
user11131551

Reputation:

Is it possible to query data from two table without a direct related column?

Let's say I have two tables, one is for Hotel and one is for Room. The column that connect them is Room.hotelId and Hotel.Id. But then I got asked to query Room data based on the likeliness of Hotel title. I can get them through a query to resolved into a list of hotelId then use it in a list of queries to get the list of room I want. But is it possible to query it in a single query?

Upvotes: 1

Views: 28

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415705

You can do something like this:

SELECT r.*
FROM Hotel h
INNER JOIN Room r ON r.HotelId = h.Id
WHERE h.Title LIKE '%' + @YourTitleHere + '%'

But you're gonna have some wrong hotel matches with a query like that. You should push back on the requirement as much as you can.

Upvotes: 1

Related Questions