How can I create multiple tables in one row in mySQL?

by Severin   Last Updated October 19, 2019 18:06 PM - source

I want to merge different data from a table into one row.

Example jsFiddle:http://sqlfiddle.com/#!9/2ed83c/10

Some example Data:

Table wp_posts:

wp_posts

Table wp_postmeta:

wp_postmeta

Table wp_term_relationships:

wp_term_relationships

Table wp_term_taxonomy:

wp_term_taxonomy

Table wp_terms:

wp_terms

The post_type orders contains the Relations (Schematic):

+----------+------------------+-------------------+
| order ID | service relation | customer relation |
+----------+------------------+-------------------+
|order 001 | Cours 1,         | Customer 1        |
|          | Eat all incl.    |                   |
+----------+------------------+-------------------+
|order 002 | Cours 1          | Customer 2        |
+----------+------------------+-------------------+
|order 003 | Cours 1,         | Customer 3        |
|          | Cours 2,         |                   |
|          | Eat all incl.    |                   |
+----------+------------------+-------------------+

I want to create the following table using a mySQL query:

+---------+--------------+-------+------------+
| Order   | Service      | Price | Customer   |
+---------+--------------+-------+------------+
| Order 1 | Cours 1      | 200   | Customer 1 |
+---------+--------------+-------+------------+
| Order 1 | Eat all incl.|  10   | Customer 1 |
+---------+--------------+-------+------------+
| Order 2 | Cours 1      | 200   | Customer 2 |
+---------+--------------+-------+------------+
| Order 3 | Cours 1      | 200   | Customer 3 |
+---------+--------------+-------+------------+
| Order 3 | Cours 2      | 150   | Customer 3 |
+---------+--------------+-------+------------+
| Order 3 | Eat all incl.|  10   | Customer 3 |
+---------+--------------+-------+------------+

What must the mySQL query be?



Related Questions



get minimum from result with group by mysql

Updated June 19, 2016 08:02 AM


MySQL missing entries in join

Updated November 12, 2016 08:02 AM

Grouping multiple records into one row

Updated April 05, 2017 00:06 AM