×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-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

*Tek-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

select distinct don't work as I thoght

select distinct don't work as I thoght

select distinct don't work as I thoght

(OP)
Hi,

I have the following Tabels:

Movies
Id...Name...TruckBrandsFId..Set
1....Navn1..1...............8
2....Navn2..2...............10
3....Navn3..3...............3
4....Navn4..4...............5
5....Navn5..5...............7
6....Navn6..6...............2
7....Navn7..7...............9
8....Navn8..8...............1
9....Navn9..1...............4
10...Navn10.3...............6

TruckBrands
Id...Name
1....Navn1
2....Navn2
3....Navn3
4....Navn4
5....Navn5
6....Navn6
7....Navn7
8....Navn8

What I want:

Id...Name...TruckBrandsFId..Set
1....Navn1..1...............8
2....Navn2..2...............10
4....Navn4..4...............5
5....Navn5..5...............7
6....Navn6..6...............2
7....Navn7..7...............9
8....Navn8..8...............1
10...Navn10.3...............6

I hope someone can help me - I cann't figure out to make af select distinct on that......or what have I to do, to get the above?

Kind regards,
simsen smile

RE: select distinct don't work as I thoght

your sample data makes no sense

can you explain what you're trying to do?

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: select distinct don't work as I thoght

(OP)
Hi r937,

I will try to explain:

I have one table; TruckBrands. In this table I have 8 entries (8 different truck brands).

My leading table; Movies I have a foreign key to TruckBrands

For each Truckbrand I now want to get the row in the Movies table, witch have that specific truckbrand AND Set is the higest number.

An example
Id   Name   TruckbrandFId   Set
8....Navn8..8...............1
10...Navn10.8...............6

Here it should take Id 10 because Set is 6 and is higher than Set 1 for Id 8.

This should be done for each TruckBrand in the TruckBrands table.
I have to rows in Movies witch have have the same truckbrand but with different "Set". Now it should take the highest number from these two.

 

RE: select distinct don't work as I thoght

(OP)
Thank you very much - that was exactly what I needed smile

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 Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close