webForumDet fria alternativet
Logga in / Bli medlem

Vad kan jag ha missat

Databaser & SQL

2 svar · 133 visningar · startad av erka

Medlem sedan dec. 19996 522 inlägg
Frågan#1

Hej. Jag har ett litet register med 50 stycken addresser, så fort jag försöker få ut något från tabellen CountryStates så kommer endast de addresser som har något i fältet stateId i tabellen distributors upp. Om jag skiter i att ta med tabellen CountryStates så får jag fram alla 50. Vad kan jag har gjort för fel i mina relationer, fält.

SELECT Distributors.DistId, Distributors.Countryname_ID, Distributors.Name, Distributors.Adress1, Distributors.Adress2, 
Distributors.StateId, Distributors.Zip, Distributors.City, CountryName.CountryName_ID, CountryName.CountryName_GB, 
CountryName.CountryCode, CountryStates.StateId, CountryStates.StateName, CountryStates.StateCode FROM Distributors INNER JOIN CountryName ON Distributors.Countryname_ID = CountryName.CountryName_ID INNER JOIN
CountryStates ON Distributors.StateId = CountryStates.StateId AND 
CountryName.CountryName_ID = CountryStates.CountryName_ID
Medlem sedan dec. 200012 464 inlägg
#2
SELECT Distributors.DistId, Distributors.Countryname_ID, Distributors.Name, Distributors.Adress1, Distributors.Adress2, 
Distributors.StateId, Distributors.Zip, Distributors.City, CountryName.CountryName_ID, CountryName.CountryName_GB, 
CountryName.CountryCode, CountryStates.StateId, CountryStates.StateName, CountryStates.StateCode FROM Distributors inner JOIN CountryName ON Distributors.Countryname_ID = CountryName.CountryName_ID [b]left outer[/b] JOIN
CountryStates ON Distributors.StateId = CountryStates.StateId AND 
CountryName.CountryName_ID = CountryStates.CountryName_ID

så borde du få med även de där ststeid inte är satt.

Medlem sedan dec. 19996 522 inlägg
#3

Tack lars g !

273 ms totalt · 4 externa anrop · v20260731065814-full.05830320
127 ms — deklarationer (db)
0 ms — hämta statistik (cache)
139 ms — hämta tråd, inlägg och bilagor (db)
132 ms — ändringar (db)