I have two SQLite tables:
- users:
id username age 1 jack 24 2 lisa 19
- images:
id username image 1 jack jackImg1.jpg 2 jack jackImg2.jpg 3 lisa lisaImg1.jpg
I use LEFT JOIN to get all jack's images:
SELECT users.*, images.image FROM users
LEFT JOIN images ON images.username = users.username
WHERE users.username = 'jack';
the result is like this:
id username age image 1 jack 24 jackImg1.jpg 1 jack 24 jackImg2.jpg
But I'd like to get a result like this:
id username age image1 image2 1 jack 24 jackImg1.jpg jackImg2.jpg
How can I achieve a result like above table?
Note: the number of images can vary from zero to any number(like 15, 20,...)
image1andimage2? What if you query several users with a different number of attached images?