Solved

Select First value from Detail table

Posted on 2006-11-08
2
815 Views
Last Modified: 2008-01-09
Hi All,

          I am working on CustomerMaster & CustomerDetail tables. In Detail table, there are many records for one customerID and CustomerID is the PK in Master table . I want to create a SQL statement which should include all the records from Master Table and first matching record from the Detail Table.
How do we write a SQL sttement.?
Any help on this problem is appreciated.

Thanks in advance.
SMV



0
Comment
Question by:smv939
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17901065
select *
from master m
join detail d
 on d.master_key = m.key
where d.somefield = ( select top 1 i.somefield from detail i where i.master_key = m.key )
0
 

Author Comment

by:smv939
ID: 17901320
Thanks so much. It worked.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can we attach PDF to table 2 46
SQL Time out only from one specific computer client 15 52
Does INTERSECT return opposite from FULL OUTER JOIN? 4 40
Query Task 8 14
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question