I have a table with this structure:
+------------+-----------------+----------+
| xreference | title | language |
+------------+-----------------+----------+
I want that to obtain something like this by means of an SQL query :
+------------+---------------+-----------------+--------------+--------------+
| xreference | title_eng | title_ita | language_eng | language_ita |
+------------+---------------+-----------------+--------------+--------------+
how can i obtain this structure? There is a method that allow to organize two records of the same table in the same row?
For example, if i have this data:
+------------+-----------------+----------+
| xreference | title | language |
+------------+-----------------+----------+
| 1 | example_title | eng |
| 1 | example_title_2 | ita |
+------------+-----------------+----------+
i want to obtain something like this:
+------------+---------------+-----------------+--------------+--------------+
| xreference | title_eng | title_ita | language_eng | language_ita |
+------------+---------------+-----------------+--------------+--------------+
| 1 | example_title | example_title_2 | eng | ita |
+------------+---------------+-----------------+--------------+--------------+
The simplest way in your case is probably conditional aggregation:
I am not sure what the last two columns are supposed to be doing.
The advantage to this method over using a
join
is two-fold. First, it is easy to add new languages. And, this will show allxreference
values, even those that have no translations in English and/or Italian.