Kevin
Kevin

Reputation: 23634

Can anyone explain to me what this query does?

I need the riposte in layman's language.

SELECT 
    t1.*
    , IF(isBranch='true','',IF(pointsweightage IS NULL,'Not Set',pointsweightage)) AS w
    , t2.id AS wid 
FROM 
    `skills_hierarchy` t1 LEFT JOIN 
    weightage t2 ON t1.pointsweightage=t2.weightage 
WHERE 
    isBranch='false' 
    AND t1.deptid=$deptid 
    AND t2.deptid=$deptid

I want the Query to be changed such that it gets me the data of the department which it does login.

Upvotes: 1

Views: 114

Answers (1)

Mitchel Sellers
Mitchel Sellers

Reputation: 63136

Well, I'm going to re-format this a bit to help you out, then I'll explain below.

SELECT 
    t1.*,
    IF(isBranch='true',
        '',
        IF(pointsweightage IS NULL,
            'Not Set',
            pointsweightage)) AS w,
    t2.id AS wid 
FROM `skills_hierarchy` t1 
    LEFT JOIN weightage t2 
        ON t1.pointsweightage=t2.weightage 
WHERE isBranch='false' 
    AND t1.deptid=$deptid 
    AND t2.deptid=$deptid

The "Select" portion gets you all values from the "skills_hierarchy" table, then a value for a column called "w". This value will be one of three things.

  1. An empty value if isBranch is equal to true
  2. A Value 'Not Set' if pointsweightage is null
  3. The value of pointsweightage if 1 and 2 do not apply

The query is already filtering out results based on a parameter value of $deptid

Upvotes: 1

Related Questions