473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Nested SQL queries ?

hi,

i have 2 tables

T1
col1, col2, col3
ID1 , col2Val1 col3Val1
ID2 , col2Val2 col3Val2
ID3 , col2Val3 col3Val3

T2
field1 , field2, field3
ID1 field2Val1 field3Val1
ID1 field2Val2 field3Val2
ID2 field2Val3 field3Val3
ID2 field2Val4 field3Val4

i.e T2.field1 is a foriegn key from T1.col1

i need an o/p that looks like

ID1, col2Val1, col3Val1, field2Val1, field3Val1, field2Val2, field3Val2
ID2, col2Val2, col3Val2, field2Val3, field3Val3, field2Val4, field3Val4
Oct 25 '07 #1
5 1761
nico5038
3,080 Expert 2GB
Hmm, looks hard to do with queries.
Does your table T2 always hold two rows for each ID or can they vary ?

Nic;o)
Oct 25 '07 #2
Hmm, looks hard to do with queries.
Does your table T2 always hold two rows for each ID or can they vary ?

Nic;o)
not two , but T2 has a fixed no. of rows corresponding to each entry in T1
Oct 28 '07 #3
nico5038
3,080 Expert 2GB
OK when it's fixed you can use the MOD function to "aggregate" the rows into one new row with all data.
Will look for two rows like:
[code=sql]
select id, field1, field2, "" as field3, ""as field4 from T2 where Autonum MOD 2 = 1
UNION
select id, "" as field1, "" as field2, field3, field4 from T2 where Autonum MOD 2 = 0
[code]

This does require to create an Autonumber field before code execution to enable the MOD to work.
Finally A GroupBy query will be needed to get the MAX value of the field values into one row.

Getting the idea ?

Nic;o)
Oct 28 '07 #4
I managed to do it !

Thanx !!
Oct 29 '07 #5
nico5038
3,080 Expert 2GB
Well done !

Success with your application !

Nic;o)
Oct 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should...
5
by: ahokdac-sql | last post by:
Hi, I'm adapting access queries to sql server and I have difficulties with the following pattern : query1 : SELECT * FROM Query2 WHERE A=@param1 query 2: SELECT * FROM Table2 WHERE B=@param2 ...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
2
by: Rashrashetta | last post by:
Dear all, I need to know how to create nested query in MS access ?? Please provide me with any link that may help as soon as possible. Thanx alot, Rashrashetta
3
by: Zlatko Matić | last post by:
Hello. I'm wondernig what is happennig whith saved pass-through queries nested in regular JET query if regular JET query just filtrates result by start/end date...Does pass-through query first...
4
by: so.intech | last post by:
for example, ret = 0; for(i=0; i<3; i ++;) { for(j=0; j<4; j++;) { for(k=0; k<3; k++;) { for(m=0; m<4; m++;) {
6
by: duke442games | last post by:
Hi Gang I am working on fixing a corrupted database (A yearly proc did not handel the conversion from year to year and now I have to fix the resulting lines in the DB). Most of my fixes I have...
3
by: jonceramic | last post by:
Hi all, I'm not sure exactly what words to use or how to Google this. (I keep coming up with BOL links.) So, I'm going to ask the group for a starting point or proper terms to even describe...
3
by: lemonade134 | last post by:
Hello, I'm creating a database in Access 2003 after not using Access for about six years. I used to use nested queries, but don't see a way to do that in the newer form of Access. Instead, the books...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.