Advertisement

05.13.2008 at 01:20PM PDT, ID: 23399299
[x]
Attachment Details

Retrieving distinct data from multiple columns

Asked by ddrhoward in MS SQL Server, SQL Server 2005, SQL Server 2008

Tags: SQL server 2000

I have a table that we'll call TI.  In TI are fields
recid     Po.       Co.Num
01         16         4521
02         17        4632
03         18         9854

Also this table joins to what we'll call T2 via recid and in T2 are fields

recid     Co.             date
01         FW        04/15/2008
01         FC        04/15/2008
02         CW       06/15/2008
03         EW       06/14/2009

In TI the primary key in the recid, but T2 doesn't have a recid because it can have more that one Company (Co.)
When writing a select statement, I would like for my query to display only distinct recids.  
01 FW  04/15/2008
02 CW   06/15/2008
03  EW   06/14/2008

Using distinct won't work because it looks at the complete row. Since the Co are different, it pulls all three. I don't need for it to pull duplicate record id.  I've using group by and union  but then again  I could be writing the query wrongStart Free Trial
 
Loading Advertisement...
 
[+][-]05.13.2008 at 01:25PM PDT, ID: 21558947

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 01:44PM PDT, ID: 21559117

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 01:47PM PDT, ID: 21559139

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 02:53PM PDT, ID: 21559641

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 12:42AM PDT, ID: 21561891

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Server 2005, SQL Server 2008
Tags: SQL server 2000
Sign Up Now!
Solution Provided By: dportas
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.14.2008 at 09:24AM PDT, ID: 21565872

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628