Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:27:10+00:00 2026-06-06T09:27:10+00:00

I have three tables as shown in below image. Note: Lead column of projectheader

  • 0

I have three tables as shown in below image.

Note: Lead column of projectheader table stores an employee id.

enter image description here

What I want to have is be able to retrieve something like the one in table my goal(Lead, displays the lead name of that employee)

I was able to do that using the query below.

SELECT DISTINCT
  projectdetails.ProjectDetailsID,
  projectheader.ProjectID,
  projectheader.ProjectName,
  projectheader.Lead,
  projectheader.StartDate,
  projectheader.EndDate,
  projectheader.Status,
  projectheader.Remarks,
  projectdetails.EmployeeID,
  employee.Firstname,
  employee.Lastname,
  Lead.Leadname
FROM
  projectheader,
  projectdetails,
  employee,
  ( SELECT
      projectheader.ProjectID AS projid,
      CONCAT(employee.Firstname,' ',employee.Lastname) AS Leadname
      FROM employee, projectheader, projectdetails 
      WHERE projectheader.ProjectID = projectdetails.ProjectID 
      AND projectheader.Lead = employee.EmployeeID
  ) AS Lead
WHERE projectheader.ProjectID = projectdetails.ProjectID
AND projectdetails.EmployeeID = employee.EmployeeID
AND projectheader.ProjectID = Lead.projid
AND projectdetails.ProjectID = Lead.projid

And got this result:
enter image description here

The query that I used is quite long and perhaps not well written, I want to know a different way on how I could achieve the same result using a better sql query either by using join or a subquery. (I added a DISTINCT on the beginning of the projectdetails.ProjectDetailsID because without it some rows are duplicated). I’m in search for a better query than the one I’m currently using.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:27:14+00:00Added an answer on June 6, 2026 at 9:27 am

    Try something like this (haven’t tested it, you can give it a try):

    SELECT
      projectdetails.ProjectDetailsID,
      projectheader.ProjectID,
      projectheader.ProjectName,
      projectheader.Lead,
      projectheader.StartDate,
      projectheader.EndDate,
      projectheader.Status,
      projectheader.Remarks,
      projectdetails.EmployeeID,
      employee.Firstname,
      employee.Lastname,
      CONCAT(Lead.Firstname,' ',Lead.Lastname) AS Leadname
    FROM
      projectheader,
      projectdetails,
      employee,
      employee as Lead
    WHERE projectheader.ProjectID = projectdetails.ProjectID
    AND projectdetails.EmployeeID = employee.EmployeeID
    AND projectheader.Lead = Lead.EmployeeID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables as shown below Emp ---- empID int empName deptID empDetails
I have three simple tables as shown below: +----+-------------+ +----+-----------+ +----+---------------+ | artists |
I have three tables with a one to many relationship as shown below. What
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
I have two tables, I want to search TermID in Table-A through TermID in
I have couple of tables in my Oracle database as shown below **IM_FP** FP_ID
I have a simple employee table that I want to display in a particular
I want to make a table layout as shown in the below screen: I
In the below image I am trying to achieve the following.I have a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.