Let's dive into a complex scenario with an illustration:
Consider a sqlite table with various fields (id, language, title, etc.)
Each title can have multiple languages associated with it.
id -- language -- title -- publication -- etc.
----------------------------------------------------------------------
1 -- Eng -- Les misérables -- 1968 -- ...
2 -- Fr -- Les misérables -- 1985 -- ...
3 -- Fr -- Les misérables -- 2001 -- ...
4 -- Eng -- Brave new world -- 1975 -- ...
5 -- Eng -- Brave new world -- 1999 -- ...
6 -- Fr -- Brave new world -- 1999 -- ...
The Challenge:
I want to retrieve the first English and French results in a single SELECT statement.
SELECT (id WHERE language='Eng') AS id1, (id WHERE language='Fr') AS id2 FROM myTable GROUP BY title
In this example, the query would output:
// The following is pseudo-JavaScript code with the SQL challenge
results.rows.item(1).id1 = 1
results.rows.item(1).id2 = 2
results.rows.item(2).id1 = 4
results.rows.item(2).id2 = 6
and so on...
Although the provided syntax is incorrect, can this be achieved through SQL?