×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

table question

table question

table question

(OP)
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




RE: table question

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources