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 8597161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:51:06+00:00 2026-06-12T00:51:06+00:00

I have a users table which contains the users information (fname, lname…etc) and a

  • 0

I have a users table which contains the users information (fname, lname…etc) and a invoices table. In the invoices table I have a field called created_id which links to the user.id that created the invoice. I also have a field called staff_id which links to the staff user.id that approved the invoice.

How can I query the first and last name for both the created_id and the staff_id in a single query? Here are a few things I’ve tried….

SELECT  
    invoices.*,
    users.fname as created_fname,
    users.lname as created_lname
FROM
    invoices
INNER JOIN users
    ON users.id = invoices.created_id;

This works, but it only gets me the person’s name that created the invoice. How can I add the staff’s name to that as well….

SELECT 
    invoices.*, 
    users.fname as created_fname, 
    users.lname as created_lname,
    users2.fname as staff_fname,
    users2.lname as staff_lname
FROM invoices, users
LEFT JOIN
    invoices,
    users AS users2
ON
    users.id = invoices.created_id,
    users.id = users2.id

That doesn’t work, but is closer. Any guidance or examples would be very helpful. Also, if you have any recommendations for good books on learning how to do more advanced MySQL queries that would be helpful too.

  • 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-12T00:51:07+00:00Added an answer on June 12, 2026 at 12:51 am

    You need to join users table twice on table Invoice.

    SELECT  a.*,
            b.fname created_firstName,
            b.lname created_LastName,
            c.fname staff_firstName,
            c.lname staff_LastName      
    FROM    Invoice a
            INNER JOIN users b
                ON a.created_id = b.id
            INNER JOIN users c
                ON a.staff_id = c.id
    

    and best thing is you can concatenate their names into one using CONCAT

    SELECT  a.*,
            CONCAT(b.fname, ' ', b.lname) created_fullName,
            CONCAT(c.fname, ' ', c.lname) staff_fullName        
    FROM    Invoice a
            INNER JOIN users b
                ON a.created_id = b.id
            INNER JOIN users c
                ON a.staff_id = c.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a table called Users, which contains your typical information: Id, Name,
I have a table called order which contains columns id , user_id , price
I have a table which contains contact information. This table has 1 column relevant
I have a table which contains a timezone offset, +1, -7, +5 etc. I
I have a database which has two tables. One table contains the information of
I have a table which contains Geo-Based information. (latitude and longitude) i would like
I currently have a user's table which contains a one-to-one relationship for Youtube OAuth
I have a table which contains User IDs, Period IDs and Qty: User Period
I have a database named Tamaris, which contains a table User. I created a
So I have a mySQL database with a 'users' table which includes a username,

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.