Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select First value from Detail table

Posted on 2006-11-08
2
Medium Priority
?
819 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

604 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