-1

Query:

SELECT DISTINCT Employee_Name, Employee_Type, Email, Birth_Date, 
        Previous_Education, Project_Name, Skill_Title
FROM Employee_T, Project_T, Skill_T, Skill_Overview_T
WHERE Employee_T.Employee_ID = Skill_T.Employee_ID 
AND Skill_T.Skill_Code = Skill_Overview_T.Skill_Code 
AND Employee_Name = 'xyz';

I am trying to display an Employee Profile in SQL. The employee works on many projects and has two skills, which is why I get lots of redundant rows for the employee information like name, email address etc. I want to show each information once only. How do I have to adjust my SQL query for that?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • We will probably need to see some concrete sample data in order to answer. Note that `DISTINCT` will only filter off rows if _all_ column values are the same. – Tim Biegeleisen Oct 10 '21 at 07:23

1 Answers1

3

First of all use the explicit join syntax. The old one with comma is deprecated almost 30 years now!

And when you do you can see that you miss a join condition for the project table:

SELECT e.Employee_Name, e.Employee_Type, Email, e.Birth_Date, e.Previous_Education, 
       p.Project_Name, s.Skill_Title
FROM Employee_T e
JOIN Project_T p ON ?????
JOIN Skill_T s ON e.Employee_ID = s.Employee_ID
JOIN Skill_Overview_T o ON s.Skill_Code = o.Skill_Code
WHERE e.Employee_Name = 'xyz';

Also my guess is that you don't need to join Skill_Overview_T table at all.

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • It still doesn't work cause it gives me the error code "not unique table/alias: project_T" – Julia Brost Oct 10 '21 at 09:40
  • @JuliaBrost the error means: `Your query contains columns which could be present with the same name in more than one table you are referencing`. – Ergest Basha Oct 10 '21 at 11:33
  • @JuliaBrost: You need to add a table name before the columns you select. That way the DB knows which table you mean. If 2 tables contain a column like `name` then you need to a the table to identfy the correct one like this: `select tablename.name`. If you use aliases for tables then you need to use them and can NOT mix like this: `select table.name, t.id from table t` – juergen d Oct 10 '21 at 12:36