Andre Andre - 8 months ago 25
PHP Question

SQL select items from one table with conditions from another

I have 2 Tables:
Accounts(ID, Name, Adress, Type)
Holidays(Name, StartDate, EndDate)

And the Type column from Accounts is a SET("Manager","Director","Administrator") for example.

The Name Column for both colums are relationed, when someone creates a holiday, the Name from table Holidays will be his name from the account that is logged in.

And i want to know if it's possible to make a SQL statement where i can take all of table 2 which the the table1.type need to be "Director" and the needs to be on holidays.


SELECT * FROM Accounts a, Holidaysh WHERE a.Name = h.Name AND a.Type = 'Director' 

This should get you all the entries you want. It's important to link a.Name to h.Name to ensure that you get the right combination.