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.
Try this:
SQL Fiddle Demo
This will give you:
Assuming that each
valuesentry in the user profile table has twofidvalues 1, 2 indicating thefirstnameandlastname.