PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 17, 2022

[FIXED] SQL - simple query and join problems

 March 17, 2022     join, phpmyadmin, sql     No comments   

Issue

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!


Solution

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 %' 


Answered By - zealous
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing