Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Dear all,
Can anyone help me out below the SQL query, please?
I have three tables A, B, and C, each table having employee and their salary, I want to get the high salary from each table in one table.
What is the SQL query for this, below the one example tables.
Ex: Table A
Employee | Salary |
David | 66000 |
Michel | 60000 |
Richard | 56000 |
Daniel | 72000 |
Maxwell | 80000 |
Ronald | 75000 |
Table B
Employee | Salary |
Raj | 90000 |
Krish | 55000 |
Mohan | 71000 |
Mary | 69000 |
Alex | 120000 |
Soham | 92000 |
Table C
Employee | Salary |
Trump | 45000 |
Modi | 59000 |
Greek | 76000 |
Joshi | 61000 |
Kevin | 83000 |
Charlet | 74000 |
Output would be like these
Table D
Employee | Salary |
Alex | 120000 |
Kevin | 83000 |
Maxwell | 80000 |
You are looking for an SQL query or do you want to do this in QlikView?
Hello Sunny Glad to you.
This query belongs to SQL database but if you are okay - I wish to see both queries in SQL and Qlikview.
Mean while I can compare what's the differences between both queries.
Thanks,
Bob.
SELECT Employee, Max(Salary) as Salary FROM tableA
Group by Employee
UNION
SELECT Employee, Max(Salary) as Salary FROM tableB
Group by Employee
UNION
SELECT Employee, Max(Salary) as Salary FROM tableC
Group by Employee;
HI Ziad,
I appreciated your response,
Still I have confuse Group by is used for aggregated, if apply Group by to employee column, its aggregates to employee.
Could you please explain me once.
Thanks,
Bob
Sunny, How to do in Qlikview? For ref, PFA.
Hi Anil
Employees:
Load Employee, Max(Salary) as Salary FROM tableA
Group by Employee
Concatenate
SELECT Employee, Max(Salary) as Salary FROM tableB
Group by Employee
Concatenate
SELECT Employee, Max(Salary) as Salary FROM tableC
Group by Employee;
I don't think so this is workable. But thanks. Have a look of my attachment
Hi Anil,
I'm unable to open that attachment, getting Qlikview error
PFA error message
Anil -
One option is to do it like this:
TableA:
LOAD *,
'TableA' as Flag;
LOAD * Inline [
Employee, Salary
David, 66000
Michel, 60000
Richard, 56000
Daniel, 72000
Maxwell, 80000
Ronald, 75000
];
TableB:
LOAD *,
'TableB' as Flag;
LOAD * Inline [
Employee, Salary
Raj, 90000
Krish, 55000
Mohan, 71000
Mary, 69000
Alex, 120000
Soham, 92000
];
TableC:
LOAD *,
'TableC' as Flag;
LOAD * Inline [
Employee, Salary
Trump, 45000
Modi, 59000
Greek, 76000
Joshi, 61000
Kevin, 83000
Charlet, 74000
];
FinalTable:
NoConcatenate
LOAD Flag,
Max(Salary) as MaxSalary,
FirstSortedValue(Employee, -Salary) as EmployeeWidMaxSalary
Resident TableA
Group By Flag;