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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:45:26+00:00 2026-06-16T00:45:26+00:00

Here I have data on five tables I would like to pull. Table 1

  • 0

Here I have data on five tables I would like to pull.

Table 1 users has three Columns:

uid, username, data

Table 2 users_order has three Columns:

uid, orders_id, users_email

Table 3 order_products has three Columns:

orders_id, product_id, product_name

Table 4 users profile values has three Columns (below is the data in the row)

uid, fid, values
1     1   firstname
1     2   lastname

So, with Table 1 – 3 I was able to write the query like this

SELECT users.uid AS uid, users.username AS username, 
       users_order.orders_id AS orderId,     
       users_order.users_email AS userEmail, 
       order_products.product_name AS  productName 
WHERE users_order.uid = users.uid
AND users_order.orders_id = order_products.orders_id
AND order_products.product_id = 5 ;

Above query will give the results of

uid   usersname   orderId   usersEmail       productName 
1    xxusername   123       xxxuser@gmail    Product 1

I would like to bring in the Table 4 data Firstname and Last Name into query results.
So, the final query will be

uid    username    orderId     usersEmail    productName    FirstName    LastName

need help on query that added the Table 4 data.

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

    Try this:

    SELECT 
      u.uid AS uid, 
      u.username AS username, 
      o.orders_id AS orderId,     
      o.users_email AS userEmail, 
      p.product_name AS  productName,
      MAX(CASE WHEN f.fid = 1 THEN `values` END) AS 'First Name',
      MAX(CASE WHEN f.fid = 2 THEN `values` END) AS 'Last Name'
    FROM users u 
    INNER JOIN users_order o ON o.uid = u.uid
    INNER JOIN order_products p ON o.orders_id = o.orders_id
    INNER JOIN usersprofile f ON u.uid = f.uid
    WHERE p.product_id = 5 
    GROUP BY u.uid, u.username, o.orders_id, o.users_email, p.product_name;
    

    SQL Fiddle Demo

    This will give you:

    | UID |   USERNAME | ORDERID |     USEREMAIL | PRODUCTNAME | FIRST NAME | LAST NAME |
    -------------------------------------------------------------------------------------
    |   1 | xxusername |     123 | xxxuser@gmail |   product 1 |        sam |       lin |
    

    Assuming that each values entry in the user profile table has two fid values 1, 2 indicating the firstname and lastname.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the issue: I have 2 data contexts that I would like to do
Here's the scenario: I have 2 tables with data, one is the 2009 version
Here is the sample data for test table I have [childId] [parentId] [present] 1
Here is what i've been trying. A form will have three tab ,like the
So here's the problem. I have data in a MySQL DB as text. The
Here I have to send and receive dynamic data using a SysV message queue.
Here's the problem: I have a data-bound list of items, basically a way for
I have a outsource data from : http://example.com/data/news.json Here is the example result after
I have hourly weather data. I've seen the function examples from here: http://casoilresource.lawr.ucdavis.edu/drupal/node/991 I'm
Here is the scenario: I have a visual that displays some data The data

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.