Search code examples
mysqlinner-join

Select inner JOIN with multiple ids


How can i read about 80 diffrent Fields from another Table with their values? without making the query too long

Table 1 Table 2

I need to combine them. There are about 80 fields.

SELECT * FROM table_1 AS t1
INNER JOIN table_2 AS t2 ON ???

Solution

  • I fear you have to do something like this

    SELECT t1.id
      ,t1.main_id,
      ,t1.web_ids
      ,t2.value as herstellerinterne_baureihebezeichnung
      ,t3.value as modell_start 
      ... 
    FROM table_1 AS t1
    LEFT JOIN table_2 AS t2 ON t2.id = t1.herstellerinterne_baureihebezeichnung
    LEFT JOIN table_2 AS t3 ON t3.id = t1.modell_start
    
    usw.
    

    for all 80 columns. Or you could build a stored procedure, where you would build a select statement by itself (loop through all columns (without the first 3) and execute it, but for that you must post your tables as text.