Skip to content
Advertisement

SQL – simple query and join problems

I believe this is a simple task, and i have asked it here before but failed to provide enough information or my attempts at it, so i do apologise for that.

I need to create a query that displays the list of clubs that provide kids playroom as one of their facilities, showing club name, state, club phone number sorted by club state.

Just really struggling with queries atm!

My database:

enter image description here

Attempt at solving this:

SELECT DISTINCT BRANCH.ClubName, BRANCH.State, FACILITY.Description
FROM FACILITY_LIST
    JOIN FACILITY
        ON FACILITY_LIST.FacilityType
    JOIN BRANCH
        ON BRANCH.BranchID
WHERE FACILITY.Description LIKE '% kids %'

This did provide the list of Facilities that provide kids playrooms, but it just repeated over and over within all the clubnames.

Any help would be appreciated!

Advertisement

Answer

Your have incorrect join. When you use join between two tables you need to join on common key between them as following.

SELECT 
    DISTINCT b.ClubName, 
    b.State, 
    f.Description
FROM FACILITY_LIST fl
JOIN FACILITY f
ON fl.FacilityType = f.FacilityType
JOIN BRANCH b
ON fl.BranchID = b.BranchID
WHERE f.Description LIKE '% kids %' 
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement