If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Repeated Value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-05, 11:26
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
Question Repeated Value

Hi I have a query that displays 5 column but I would like to supress the repeated values from one of them....

like this

__Event___|___Reference___|___Name___|____Date____ _|
________1_|__AB01000005__|__Diogo____|__01/01/2005_|
________2_|__AB01000005__|__Diogo____|__02/01/2005_|
________3_|__AB01000005__|__Diogo____|__03/01/2005_|
________4_|__AB01000001__|__MAria____|__04/01/2005_|
________5_|__AB01000002__|__Joao_____|__05/01/2005_|


this table is what I am getting
I want it to return this

__Event___|__Reference____|__Name____|___Date_____ __|
_______3__|__AB01000005__|__Diogo____|___03/01/2005_|
_______4__|__AB01000001__|__Maria____|___04/01/2005_|
_______5__|__AB01000002__|__Joao____|____05/01/2005_|

This way I only get the latest reference.....

There is any way to do this?
Reply With Quote
  #2 (permalink)  
Old 01-27-05, 11:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select Event
     , Reference
     , Name
     , theDate
  from yourtable as t
 where theDate
     = ( select max(theDate)
           from yourtable
          where Reference = t.Reference )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-27-05, 11:52
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
That does not seem a good solution since I am using 3 tables to get the values
if you have another ideia I would apreciate
Reply With Quote
  #4 (permalink)  
Old 01-27-05, 11:58
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
What is the difference between this problem and your other one entitled "Can't Use Distinct Here"?
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 01-27-05, 12:17
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
guess this one is less detailed.....

Oh if you don't mind.... I have 2 tables.... one as all the references as text, and the other only have the used ones.....

I wantes to query all of the references that are not being used....

I think this one is easy but I am a newbie at SQL!!!

guess you can tell me how to do it
Reply With Quote
  #6 (permalink)  
Old 01-27-05, 12:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by santal_maluko
guess you can tell me how to do it
actually, we would prefer that you do a little bit of this work yourself

hint: left outer join
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-27-05, 12:43
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
I've been trying something like this

SELECT Badges.BadgeReference
FROM Badges, Visitors
WHERE (((Badges.BadgeReference) Like Not[Visitors].[VisitorReference]));

And it does not work
then I tryied

SELECT Badges.BadgeReference
FROM Badges LEFT JOIN Visitors ON Badges.BadgeReference = Visitors.VisitorReference
WHERE (((Badges.BadgeReference) Like Not [Visitors].[VisitorReference]));

Nothing.... and finally

SELECT Badges.BadgeReference
FROM Badges Right JOIN Visitors ON Badges.BadgeReference = Visitors.VisitorReference
WHERE (((Badges.BadgeReference) Like Not [Visitors].[VisitorReference]));
Reply With Quote
  #8 (permalink)  
Old 01-27-05, 12:44
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
oooooohh.... forget.... outer joins... I'll be trying
hehehe
Reply With Quote
  #9 (permalink)  
Old 01-27-05, 12:49
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
ok guess I didn't make it.....
what a failure!!!!
Reply With Quote
  #10 (permalink)  
Old 01-27-05, 12:51
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
...

I can only get the ones that I am using and not the inverse...
Reply With Quote
  #11 (permalink)  
Old 01-27-05, 13:06
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
keep looking , you are almost there

what are you using as a reference for left outer join?

textbook? tutorial web site?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 01-28-05, 05:06
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
I'm trying by myself, and searching for something on the internet...
Reply With Quote
  #13 (permalink)  
Old 01-28-05, 05:26
santal_maluko santal_maluko is offline
Registered User
 
Join Date: Jan 2005
Posts: 23
SELECT Badges.BadgeReference
FROM Badges Left Outer Join Visitors On Badges.BadgeReference = Visitors.VisitorReference
WHERE Badges.BadgeReference <> Visitors.VIsitorReference

I've reached here....... It returns nothing.... it was suposed to return 1,2,3 and 4, the 5 was being used....

if I take off the where it shows all the references including the 5 and I don't want it to do it.....

Getting desperated with this one
Reply With Quote
  #14 (permalink)  
Old 01-28-05, 06:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
you need a good SQL tutorial

there are several on my SQL Links page

meanwhile, in a LEFT OUTER JOIN, rows from the left table which have no matching row in the right table are still returned in the results, but the columns from the right table are all null

therefore if all you want is the unmatched rows,

SELECT Badges.BadgeReference
FROM Badges Left Outer Join Visitors
On Badges.BadgeReference = Visitors.VisitorReference
WHERE Visitors.VIsitorReference is null

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On