Concatenate multiple rows from one row from two databases

I have two tables in MySQL. One with orders. One with buyers. The buyers table is complex. I want to concatenate multiple rows from Buyers table into one row in my issue. This is what the tables look like what I am trying to achieve ... Is this possible?

ORDER TABLE

ID      PRDCT_ID    TITLE       ORDER_TYPE
219     2           Product2    Shop_Order
220     2           Product2    Shop_Order
221     1           Product1    WH_Order

      

BUYER table:

ID  ORDER_ID    BUYER_KEY   BUYER_VALUE
43  219         first_name  Rebecca
44  219         last_name   DeVore
45  219         email       rebecca.devore@domain.com
46  220         first_name  Jesse
47  220         last_name   Lawrence
48  220         email       jesse@domain.com
49  221         first_name  Gary
50  221         last_name   Darrel
51  221         email       garydary@domain.com

      

Here I want the desired output to be ...

ORDERS.ID   ORDERS.TITLE    ORDERS.ORDER_TYPE   "First Name"            "Last Name"             "Email"
219         Product2        Shop_Order          Rebecca                 DeVore                  rebecca.devore@domain.com
220         Product2        Shop_Order          Jesse                   Lawrence                jessie@domain.com
221         Product1        WH_Order            Gary                    Darrel                  garyday@domain.com  

      

I haven't closed the code yet. I would call myself a MySQL newbie, but I know enough to make myself dangerous. But, just so you can laugh at my attempt ... here's where I am with the code; It works great to only return the lol name:

SELECT * 
FROM BUYER a, 
    ORDERS b 
WHERE a.post_id=b.id
AND b.post_type= "Shop_Order"
AND a.meta_key="first_name" 

      

Edit; This question has been flagged as a duplicate. My question changes a bit. The answer to the question that this was marked as a duplicate suggests creating a new table in the database, which I cannot do. I will limit myself to these two tables only.

+3
mysql


source to share


No one has answered this question yet

See similar questions:

2
Pivot table using MySQL
0
mySQL - create a new table using data and columns from three tables

or similar:

1086
How do I connect to a MySQL database in Python?
1069
Can multiple MySQL rows be concatenated into one field?
1030
SQL selects only rows with maximum value in column
802
How to quickly rename MySQL database (change schema name)?
769
How to get the sizes of MySQL database tables?
734
How do I specify a unique constraint for multiple columns in MySQL?
425
MySQL fetches 10 random rows from 600K rows fast
368
Compare two MySQL databases
350
Inserting multiple lines in mysql
2
problems arise when developing a database for an online fashion store



All Articles
Loading...
X
Show
Funny
Dev
Pics