Hi,
As i am not much of an SQL person, would need some kind helpIf anyone could provide some help in querying some data off 3 tables.
table1
=====
empid - surname - name - contact
---------------------------------
1 - a - z - 123
2 - b - y - 234
3 - c - x - 345
table2
=====
condid - empid
-------------
A1 - 1
A2 - 1
A3 - 1
A1 - 2
A3 - 2
table3
=====
condid - conddesc
A1 - employ
A2 - probation
A3 - Resignwhat i would need is to have the query to show the report as
empid - surname - name - contact - condition1 - condition2 - condition3
----------------------------------------------------------------------
1 - a - z - 123 - employ - probation - resign
2 - b - y - 234 - employ - resign -
3 - c - x - 345 - - -
can any sql Gurus help?
I'm no guru, but I can advise you to read up on the 'join' command. Check out mysqljoin.com
SQL is very good at delivering sets of data. This outer join: SELECT table1.empid, table1.surname, table1.name, table1.contact, table3.conddesc
FROM table1
LEFT OUTER JOIN
(table2
INNER JOIN table3
ON table2.condid = table3.condid)
ON table1.empid = table2.empid
ORDER BY table1.empiddelivers all the data required:
empid surname name contact conddesc 1 a z 123 probation 1 a z 123 employ 1 a z 123 Resign 2 b y 234 employ 2 b y 234 Resign 3 c x 345The desired format is a variable number of columns so set theory will not work in my opinion. A procedural language solution is required for once the data is obtained from SQL.
Not knowing your database, I cannot help you further. Let me know if you have any questions or comments.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |