tags:

views:

78

answers:

1

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.

+1  A: 

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

Mitchel Sellers
excellent, the problem here is i am not getting the other department ID values just t1.deptid works.... i was having a doubt over the query but now feel there is some flaw in my business logic. Thanks for explaining my own query again.