Is it possible to generate a MYSQL query of more tables with values of one table column as more query columns?

Koen de Haan

I have more tables, which I want to combine together for generate a CSV file what our backoffice system can read. I have 1 table with Product information and an other table with language information. The databases are build up as the following example:

Product database:

<table>
    <tr>
        <td>id</td><td>productnumber</td><td>price</td><td>name_id</td>
    </tr>
    <tr>
        <td>1</td><td>ABC123</td><td>10.00</td><td>1</td>
    </tr>
    <tr>
        <td>2</td><td>DEF456</td><td>15.00</td><td>2</td>
    </tr>
</table>

Name database:

<table>
    <tr>
        <td>id</td><td>name_id</td><td>name</td><td>language_id</td>
    </tr>
    <tr>
        <td>1</td><td>1</td><td>Cheese</td><td>1</td>
    </tr>
    <tr>
        <td>2</td><td>1</td><td>Fromagi</td><td>2</td>
    </tr>
    <tr>
        <td>3</td><td>1</td><td>Kase</td><td>3</td>
    </tr>
    <tr>
        <td>4</td><td>2</td><td>Water</td><td>1</td>
    </tr>
    <tr>
        <td>5</td><td>2</td><td>Acqua</td><td>2</td>
    </tr>
    <tr>
        <td>6</td><td>2</td><td>Wasser</td><td>3</td>
    </tr>
</table>

Language database:

<table>
    <tr>
        <td>id</td><td>Language</td>
    </tr>
    <tr>
        <td>1</td><td>English</td>
    </tr>
    <tr>
        <td>2</td><td>Italian</td>
    </tr>
    <tr>
        <td>3</td><td>German</td>
    </tr>
</table>

What I want to have as output for the CSV file is like this:
Productnumber + Price + Name_EN + Name_IT + Name_DE

So:
ABC123 | 10.00 | Cheese | Fromagi | Kase
DEF456 | 15.00 | Water . | Acqua . . | Wasser

Is there a way how to achieve this?

If you need more information, just let me know! Thank you all in advance.
Best regards,

Koen de Haan

slaakso

You can join the name table multiple times with the Product table.

select p.id, p.productnumber, p.price, en.name, it.name, de.name
from Product p
  join Name en on en.name_id=p.name_id and en.language_id=1
  join Name it on it.name_id=p.name_id and it.language_id=2
  join Name de on de.name_id=p.name_id and de.language_id=3

For the future, it is better to show the actual table create script rather than some HTML code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Query if array column contains one or more values

Get sum of more than one table columns with a single query

MySQL query to find if a value of one column in one table is between two values in two columns on another table

How sum the more than one select query in a single column in mysql?

is it possible to use more than 1 query in mysql?

How to match a column result from query result to a table column value and get more columns from same table?

Correlated Query with more than one table SQL

Tables showing in phpmyadmin but not query + more

Making a SQL query that selects of list of values from more than one column

How to write SQL JOIN Query for get results when one table id existing in more than one columns in other table

Is it possible to combine these 4 queries into one more efficient query?

SQL query to sum two or more columns and displaying them in the other column

How to select information from more then one table in MySQL Database using PHP and mySQli, has to be combined single query

Is it more efficient to split a large table into several tables, or stick with one, in MySQL?

PostgreSQL DROP COLUMN: Remove One or More Columns of a Table

How to combine two or more columns of data table to one column?

Go Using db.Query to return more than one column

SQL Filter query if column has more than one distinct value

Add source column in QUERY with more than one data sources

Mongo Query to search one or more values are present in an array field of a document

MySQL select a set of columns with more than one variation in another column

how to add one more table to already complicated query

SQL query is showing error with more than one join on same table

Query to count rows and more specific rows in one table

MySQL ignore query results with column that appears more than once

PDO MySQL query failing with more than one comparison operator

MYSQL IF (SELECT) query returns more than one row

MySQL query for adding one or more elements to comma separated string list

MySQL error when submitting more that one query using vba

TOP Ranking

HotTag

Archive