Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

mySQL Berbeda Bergabung?

Coba ini:

SELECT     a.locale, c.text AS text_1, d.text AS text_2
FROM       (SELECT DISTINCT locale FROM i18n) a
CROSS JOIN table_1 b
LEFT JOIN  i18n c ON b.text_1 = c.id_i18n AND a.locale = c.locale
LEFT JOIN  i18n d ON b.text_2 = d.id_i18n AND a.locale = d.locale

Demo SQLFiddle

EDIT :Ini mungkin bekerja lebih baik:

SELECT
    a.locale, b.text_1, c.text_2
FROM
    (SELECT DISTINCT locale FROM i18n) a
LEFT JOIN
(
    SELECT b.locale, b.text AS text_1
    FROM   table_1 a
    JOIN   i18n b ON a.text_1 = b.id_i18n
) b ON a.locale = b.locale
LEFT JOIN
(
    SELECT b.locale, b.text AS text_2
    FROM   table_1 a
    JOIN   i18n b ON a.text_2 = b.id_i18n
) c ON a.locale = c.locale

Demo SQLFiddle



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MySQL - JUMLAH Bersyarat dengan GROUP BY

  2. Menutup Koneksi JDBC di Pool

  3. Bagaimana cara menghitung kata di MySQL/pengganti ekspresi reguler?

  4. penghapusan data duplikat mysql

  5. Perbarui beberapa baris dengan id yang sama menggunakan foreach loop