Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

table question

Status
Not open for further replies.

abbiz

Civil/Environmental
Joined
Oct 27, 2005
Messages
1
Location
SE
SELECT DISTINCT
countries.land,
CASE WHEN visits.trotterid='2'
THEN visits.trotterid
ELSE '0' end test

FROM countries
left JOIN visits
ON countries.landid=visits.landid

I have a website with a list of countries(countries.land)
Customer should after registrating(trotterid) shoose a country or more from the list. The site should remember the shoosen countries. I can list as below with the above script, but I don´t want denmark to be listed twise.
Any Ideas?

land test

sweden 2
Danmark 0
Damnark 2
Norge 0
Finland 0


table countries

landid land
1 sverige
2 Danmark
3 Norge
4 Finland

table trotter
trotterid namn email
1 Albin at@prologic.se
2 kalle kalle@prologic.se

table visits
nr landid trotterid
1 1 2
2 2 1
3 2 2




 
The DISTINCT clause has no meaning here since Danmark was choosen by Albin and Kalle, each one with different id. The CASE clause looks like you want to filter Kalle visits only.
So I translate your question like this: I want to know what Kalle want to visit? If this is the case then the SQL is:

select countries.land, visits.trotterid from visits
join countries on countries.landid=visits.landid
where visits.trotterid=2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top