Hi,
i have a php-page with an mysql-connection and have a problem with left and right join query. i have two tables with two selectboxes on the page.
table1 (laenderliste):
id,kontinent,land,hauptstadt,iso2,iso3,ioc,domain,waehrung,vorwahl
1 Asien Deutschland Berlin DE DEU GER .de EUR 49
2 Asien Afghanistan Kabul AF AFG AFG .af AFN 93
3 Nordamerika Aruba Oranjestad AW ABW ARU .aw ANG 297
table2 (regionen):
id,vid,iso2
1 1 0 DE
2 2 0 DE
3 2 0 AF
4 2 1 DE
5 2 1 AF
6 3 0 DE
7 4 0 DE
8 2 2 DE
9 2 2 AF
10 5 0 DE
now, i would have all countrys (land on table1) who's not in table2. the field iso2 where the key to compare the two tables.
sql-query:
$sql = "SELECT l.iso2, l.land FROM laenderliste l LEFT JOIN regionen r ON l.iso2 = r.iso2 WHERE r.vid <> '$vid'";
whats wrong in my sql-query ? can someone help me please ? thanks
Page 1 of 1
SQL LEFT OR RIGHT JOIN ? Problems with join in sql-query
#2
Posted 13 January 2011 - 02:09 AM
melnib00ne, on 04 May 2010 - 04:47 AM, said:
Hi,
i have a php-page with an mysql-connection and have a problem with left and right join query. i have two tables with two selectboxes on the page.
table1 (laenderliste):
id,kontinent,land,hauptstadt,iso2,iso3,ioc,domain,waehrung,vorwahl
1 Asien Deutschland Berlin DE DEU GER .de EUR 49
2 Asien Afghanistan Kabul AF AFG AFG .af AFN 93
3 Nordamerika Aruba Oranjestad AW ABW ARU .aw ANG 297
table2 (regionen):
id,vid,iso2
1 1 0 DE
2 2 0 DE
3 2 0 AF
4 2 1 DE
5 2 1 AF
6 3 0 DE
7 4 0 DE
8 2 2 DE
9 2 2 AF
10 5 0 DE
now, i would have all countrys (land on table1) who's not in table2. the field iso2 where the key to compare the two tables.
sql-query:
$sql = "SELECT l.iso2, l.land FROM laenderliste l LEFT JOIN regionen r ON l.iso2 = r.iso2 WHERE r.vid <> '$vid'";
whats wrong in my sql-query ? can someone help me please ? thanks
i have a php-page with an mysql-connection and have a problem with left and right join query. i have two tables with two selectboxes on the page.
table1 (laenderliste):
id,kontinent,land,hauptstadt,iso2,iso3,ioc,domain,waehrung,vorwahl
1 Asien Deutschland Berlin DE DEU GER .de EUR 49
2 Asien Afghanistan Kabul AF AFG AFG .af AFN 93
3 Nordamerika Aruba Oranjestad AW ABW ARU .aw ANG 297
table2 (regionen):
id,vid,iso2
1 1 0 DE
2 2 0 DE
3 2 0 AF
4 2 1 DE
5 2 1 AF
6 3 0 DE
7 4 0 DE
8 2 2 DE
9 2 2 AF
10 5 0 DE
now, i would have all countrys (land on table1) who's not in table2. the field iso2 where the key to compare the two tables.
sql-query:
$sql = "SELECT l.iso2, l.land FROM laenderliste l LEFT JOIN regionen r ON l.iso2 = r.iso2 WHERE r.vid <> '$vid'";
whats wrong in my sql-query ? can someone help me please ? thanks
$sql = "SELECT a.iso2,a.land FROM laenderliste a, regionen b WHERE a.iso2 = b.iso2 AND b.vid <> '$vid'";
Share this topic:
Page 1 of 1



Help
Back to top









