Click here to Skip to main content
15,867,921 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,i have three tables
first table contains languages(id,languagename) english, chinese, etc.,
second table contains its translations .
now i want to convert my first table rows into columns and display the data side by side.

any help.
Posted
Comments
Member 11807562 21-Nov-15 7:45am    
any help with my query
Krunal Rohit 21-Nov-15 12:06pm    
What have you done so far ?

-KR

1 solution

As SQLLite doesn't have PIVOT feature, you can do a trick to get it done.
Create a temporary table with the structure same as you want your output be. Then insert the data using select query from the translation table to the temporary table. Then show the result from temporary table and at last drop the temporary table.

For Example:
Language Table
Id	Lang
1	English
2	Chinese
3	Hindi


Translation Table
LangId	Trans
1	this is a sample text
1	this is another sample text
2	let suppose it is in chinese
3	let suppose it is in hindi


Temp Table
SQL
CREATE TABLE temp_table(EngTrans VARCHAR(255), ChiTrans VARCHAR(255), HinTrans VARCHAR(255))

INSERT INTO temp_table (EngTrans)
SELECT Trans FROM TransTable
WHERE Id=1

INSERT INTO temp_table (ChiTrans)
SELECT Trans FROM TransTable
WHERE Id=2

INSERT INTO temp_table (HinTrans)
SELECT Trans FROM TransTable
WHERE Id=3


You can loop for the Language table and make the insert statement dynamic, but I am not sure if SQLLite supports loop or cursor.

Although it is not a direct answer but can do the job.
Hope, it helps :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900