Hello everyone,
I have two tables (cities and images)
table cities
-----------
cityID
cityName
cityShow
table images
------------
imageID
imageName
imagePath
cityID
cityID = 1 cityName = Paris cityShow = 'Y'
cityID = 2 cityName = Berlin cityShow = 'Y'
cityID = 3 cityName = New York cityShow = 'Y'
cityID = 4 cityName = Prag cityShow = 'N'
etc...
imageID = 1 paris1 cityID = 1 imagePath = paris1.jpg
imageID = 2 paris2 cityID = 1 imagePath = paris2.jpg
imageID = 3 paris3 cityID = 1 imagePath = paris3.jpg
imageID = 4 berlin1 cityID = 2 imagePath = berlin1.jpg
imageID = 5 newyork cityID = 3 imagePath = newyork1.jpg
imageID = 6 prag cityID = 4 imagePath = prag1.jpg
etc...
I tried with this query
but I got a duplicate data for cities.cityID.
cityID=1 cityName=Paris imageName=paris1 imagePath=paris1.jpg
cityID=1 cityName=Paris imageName=paris2 imagePath=paris2.jpg
cityID=1 cityName=Paris imageName=paris3 imagePath=paris3.jpg
cityID=2 cityName=Berlin imageName=berlin imagePath=berlin1.jpg
cityID=3 cityName=NewYork imageName=newyork imagePath=newyork1.jpg
As a result wanted to get the following results:
cityID=1 cityName=Paris imageName=paris1 imagePath=paris1.jpg
cityID=2 cityName=Berlin imageName=berlin imagePath=berlin1.jpg
cityID=3 cityName=NewYork imageName=newyork imagePath=newyork1.jpg
City of Prague is not shown because cityShow = N (No).
Thanks everyone!
Best Regards!
I have two tables (cities and images)
table cities
-----------
cityID
cityName
cityShow
table images
------------
imageID
imageName
imagePath
cityID
cityID = 1 cityName = Paris cityShow = 'Y'
cityID = 2 cityName = Berlin cityShow = 'Y'
cityID = 3 cityName = New York cityShow = 'Y'
cityID = 4 cityName = Prag cityShow = 'N'
etc...
imageID = 1 paris1 cityID = 1 imagePath = paris1.jpg
imageID = 2 paris2 cityID = 1 imagePath = paris2.jpg
imageID = 3 paris3 cityID = 1 imagePath = paris3.jpg
imageID = 4 berlin1 cityID = 2 imagePath = berlin1.jpg
imageID = 5 newyork cityID = 3 imagePath = newyork1.jpg
imageID = 6 prag cityID = 4 imagePath = prag1.jpg
etc...
I tried with this query
Code:
SELECT cities.cityName, cities.cityID, images.imagePath, images.imageName
FROM cities LEFT JOIN images ON cities.cityID=images.cityID
WHERE cities.cityID=images.cityID AND cities.cityShow = 'Y'
but I got a duplicate data for cities.cityID.
cityID=1 cityName=Paris imageName=paris1 imagePath=paris1.jpg
cityID=1 cityName=Paris imageName=paris2 imagePath=paris2.jpg
cityID=1 cityName=Paris imageName=paris3 imagePath=paris3.jpg
cityID=2 cityName=Berlin imageName=berlin imagePath=berlin1.jpg
cityID=3 cityName=NewYork imageName=newyork imagePath=newyork1.jpg
As a result wanted to get the following results:
cityID=1 cityName=Paris imageName=paris1 imagePath=paris1.jpg
cityID=2 cityName=Berlin imageName=berlin imagePath=berlin1.jpg
cityID=3 cityName=NewYork imageName=newyork imagePath=newyork1.jpg
City of Prague is not shown because cityShow = N (No).
Thanks everyone!
Best Regards!