Answer the question
In order to leave comments, you need to log in
How to make SQL query to four tables?
The bottom line is this - there are recipient tables - clients, human - additional information about clients (including date of birth), tables have the same id, they can be linked by them
reservation - these are applications from tourists, it indicates who issued (humanid). which tourists belong to the application is recorded in the people table.
It is necessary - for the manager (reservation.humanid) whose humanid we know in advance, to find the people (recipient) whom he sent on a trip and who have a birthday today. I came up with this request
SELECT *
FROM [samo7.0.2].[dbo].[recipient] t1
RIGHT JOIN [samo7.0.2].[dbo].[human] t2 ON t2.id = t1.id
RIGHT JOIN [samo7.0.2].[dbo].[people] t4 ON t1.id = t4.humanid
RIGHT JOIN [samo7.0.2].[dbo].[reservation] t3 ON t3.id = t4.reservationid
WHERE MONTH(t2.born) = 4 AND (DAY(t2.born) = 9) AND t3.humanid = ?
Answer the question
In order to leave comments, you need to log in
The last by what criteria? by date? Sort by date and in select top 1 add.
reservation to accept again, by recipient.id.
current day - date or day of the week? select DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question