The Royal Nick Humphrey Global World IT Forum, Home Edition  

Go Back   The Royal Nick Humphrey Global World IT Forum, Home Edition > Programmering Forum > Databaser og SQL > Oracle forum
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-10, 11:40
Nickleus's Avatar
Nickleus Nickleus is offline
Nick Humphrey - Admin
 
Join Date: 06 Apr 2004
Location: Noreg
Posts: 2,794
Send a message via MSN to Nickleus Send a message via Skype™ to Nickleus
Default oracle sql - how to select distinct one parameter in query with many parameters

i have an oracle database table, freightcostdeviation, that contains columns and rows that look like this:
Quote:
MBRID | FREIGHTERMEMBERID | FREIGHTERNAME | DATECREATED
Grocer A | DanTestTransporter | Dan Test Transporter | 2009-02-01
Grocer A | Tollfreighter | <null> | 2009-01-01
Grocer A | TransporterPlus | Transporter Plus AS | 2009-05-16
Grocer A | FreightNorway | Freight Norway Shipping Supply Chain AS | 2008-12-04
Grocer A | Tollfreighter | Tollfreighter | 2009-03-12
Grocer A | FreightNorway | Freight Norway Supply Chain AS | 2009-09-27
Grocer B | NorwegianShipping | Norwegian Shipping AS | 2009-08-30
there are other columns in the table, but these are the relevant ones. i want a resultset with a distinct freightermemberid column (no duplicates) with only the newest freightername. i dont need the datecreated in the resultset. i only want results for Grocer A.

heres how i solved the problem:
Code:
SELECT t1.freightermemberid, t1.freightername
FROM freightcostdeviation t1
WHERE t1.datecreated IN (
    SELECT max(t2.datecreated)
    FROM freightcostdeviation t2
    WHERE t2.mbrid='Grocer A' AND t2.freightermemberid = t1.freightermemberid
);
the result looks like this:
Quote:
FREIGHTERMEMBERID | FREIGHTERNAME
DanTestTransporter | Dan Test Transporter
TransporterPlus | Transporter Plus AS
Tollfreighter | Tollfreighter
FreightNorway | Freight Norway Supply Chain AS
__________________
Nick Humphrey
Download for free my experimental music, art, poetry and pictures.
My album Classic E B-sides can be purchased on both itunes and amazon.com.
Help me improve my phrasebook of world languages.
I offer remote healing services.
My blog.

Last edited by Nickleus : 05-02-10 at 11:46.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
hvordan oppgradere fra oracle 8i database til oracle 9i - migrere fra winxp to linux Nickleus Oracle forum 5 17-12-08 12:25
free open source database query gui alternative to sqlplus Nickleus Oracle forum 0 29-01-08 13:14
Cygwin - FIND: Parameter format not correct Nickleus Cygwin forum 0 17-02-06 15:31
Syntax error in number in query expression '22.22.22.22' Nickleus Databaser og SQL 0 15-12-04 10:40
Hva betyr Google parameter c2coff? Nickleus Google Forum 0 18-11-04 14:36


All times are GMT +2. The time now is 03:50.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Check out my phrasebook
All rights reserved 2004-2009