Hi,
Iam trying to figure out the query to achieve the output depicted below
create table master (
iss_dtl_seq_nbr int
)
create table child1(
iss_dtl_seq_nbr int,
line_no int
)
create table child2(
iss_dtl_seq_nbr int,
line_no int
)
insert into master
select 1
insert into child1
select 1, 1
insert into child1
select 1, 2
insert into child2
select 1, 1
insert into child2
select 1, 2
insert into child2
select 1, 3
SELECT MASTER.ISS_DTL_SEQ_NBR,CHILD1.LINE_NO, CHILD2.LINE_NO
FROM CHILD1, CHILD2, MASTER
WHERE MASTER.ISS_DTL_SEQ_NBR = CHILD1.ISS_DTL_SEQ_NBR
AND MASTER.ISS_DTL_SEQ_NBR = CHILD2.ISS_DTL_SEQ_NBR
AND CHILD1.LINE_NO = CHILD2.LINE_NO
ORDER BY CHILD1.LINE_NO, CHILD2.LINE_NO
Expected Output:
ISS_DTL_SEQ_NBR LINE_NO LINE_NO
--------------- ----------- -----------
1 1 1
1 2 2
1 NULL 3
Can anybody help with the query to achieve this?
Thanks. 2 1297
On 9 Sep 2004 09:33:21 -0700, Sudhir wrote: Hi, Iam trying to figure out the query to achieve the output depicted below
create table master ( iss_dtl_seq_nbr int )
create table child1( iss_dtl_seq_nbr int, line_no int )
create table child2( iss_dtl_seq_nbr int, line_no int )
insert into master select 1
insert into child1 select 1, 1 insert into child1 select 1, 2
insert into child2 select 1, 1
insert into child2 select 1, 2
insert into child2 select 1, 3
SELECT MASTER.ISS_DTL_SEQ_NBR,CHILD1.LINE_NO, CHILD2.LINE_NO FROM CHILD1, CHILD2, MASTER WHERE MASTER.ISS_DTL_SEQ_NBR = CHILD1.ISS_DTL_SEQ_NBR AND MASTER.ISS_DTL_SEQ_NBR = CHILD2.ISS_DTL_SEQ_NBR AND CHILD1.LINE_NO = CHILD2.LINE_NO ORDER BY CHILD1.LINE_NO, CHILD2.LINE_NO
Expected Output:
ISS_DTL_SEQ_NBR LINE_NO LINE_NO --------------- ----------- ----------- 1 1 1 1 2 2 1 NULL 3
Can anybody help with the query to achieve this?
Thanks.
Hi Sudhir,
Thanks for providing the statements to recreate your table structure and
data. The following query will produce the expected output:
select coalesce(master.iss_dtl_seq_nbr, child2.iss_dtl_seq_nbr) AS
iss_dtl_seq_nbr,
child1.line_no, child2.line_no
from master
inner join child1
on master.iss_dtl_seq_nbr = child1.iss_dtl_seq_nbr
right outer join child2
on child1.iss_dtl_seq_nbr = child2.iss_dtl_seq_nbr
and child1.line_no = child2.line_no
order by child2.line_no, child1.line_no
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Try this:
select master.iss_dtl_seq_nbr, child1.line_no, child2.line_no
from child1 full outer join child2 on child1.iss_dtl_seq_nbr =
child2.iss_dtl_seq_nbr and child1.line_no = child2.line_no
join master on master.iss_dtl_seq_nbr =
isnull(child1.iss_dtl_seq_nbr, child2.iss_dtl_seq_nbr)
Shervin s.******@gmail.com (Sudhir) wrote in message news:<80**************************@posting.google. com>... Hi, Iam trying to figure out the query to achieve the output depicted below
create table master ( iss_dtl_seq_nbr int )
create table child1( iss_dtl_seq_nbr int, line_no int )
create table child2( iss_dtl_seq_nbr int, line_no int )
insert into master select 1
insert into child1 select 1, 1 insert into child1 select 1, 2
insert into child2 select 1, 1
insert into child2 select 1, 2
insert into child2 select 1, 3
SELECT MASTER.ISS_DTL_SEQ_NBR,CHILD1.LINE_NO, CHILD2.LINE_NO FROM CHILD1, CHILD2, MASTER WHERE MASTER.ISS_DTL_SEQ_NBR = CHILD1.ISS_DTL_SEQ_NBR AND MASTER.ISS_DTL_SEQ_NBR = CHILD2.ISS_DTL_SEQ_NBR AND CHILD1.LINE_NO = CHILD2.LINE_NO ORDER BY CHILD1.LINE_NO, CHILD2.LINE_NO
Expected Output:
ISS_DTL_SEQ_NBR LINE_NO LINE_NO --------------- ----------- ----------- 1 1 1 1 2 2 1 NULL 3
Can anybody help with the query to achieve this?
Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James |
last post by:
My form and results are on one page.
If I use :
if ($Company) {
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}
|
by: netpurpose |
last post by:
I need to extract data from this table to find the lowest prices of
each product as of today. The product will be listed/grouped by the
name only, discarding the product code - I use...
|
by: Dom Boyce |
last post by:
Hi
First up, I am using MS Access 2002.
I have a database which records analyst rating changes for a list of
companies on a daily basis. Unfortunately, the database has been set
up (by my...
|
by: Andrew McNab |
last post by:
Hi folks,
I have a problem with an MS Access SQL query which is being used in an
Access Report, and am wondering if anyone can help.
Basically, my query (shown below) gets some records from a...
|
by: Steve Patrick |
last post by:
Hi All
You guys are my last hope, despite spending money on books and hours reading
them I still can not achieve the results I need.
I have designed a database in Access 2000 based on 1 table,...
|
by: Alan Lane |
last post by:
Hello world:
I'm including both code and examples of query output. I appologize if
that makes this message longer than it should be.
Anyway, I need to change the query below into a pivot table...
|
by: Takeadoe |
last post by:
Dear NG,
Can someone assist me with writing the little code that is needed to
run an update table query each time the database is opened? From what
I've been able to glean from this group, the...
|
by: mcmahonb |
last post by:
Hey people...
I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
|
by: n |
last post by:
Hello! Here is a problem I hope you can point me to a solution. It
Problem: A teacher needs to know which lesson to teach.
A school has a curriculum with 26 lessons, A-Z.
For a given class,...
|
by: Jo |
last post by:
Hi there,
I'm Jo and it's the first time I've posted here. I'm in process of creating
a database at work and have come a little unstuck.....I'm a bit of a novice
and wondered if anyone could...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |