473,395 Members | 1,464 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,395 software developers and data experts.

Nested SQL?

blyxx86
256 100+
Good Morning,

I'm attempting to write a single SQL statement that will accomplish the following...

Expand|Select|Wrap|Line Numbers
  1. table_a
  2. PK INT table_a_id
  3. VARCHAR ref_num
  4.  
  5. table_b
  6. PK INT table_b_id
  7. FK INT table_a_id
  8. DATETIME insert_date
  9. VARCHAR note
  10.  
This is a sample of a single row I want to pull from the data...

Expand|Select|Wrap|Line Numbers
  1. a.ref_num   b.note
  2. 0001          Note1
  3.                  Note2
  4.                  Note3
  5.  
The major thing I want to accomplish is having a.ref_num appear only once and loop through the notes to appear as a single row.

I currently am using two arrays within PHP to handle the construction of this, but I feel like it is losing efficiency if it can be done within the SQL syntax.

Any help would be appreciated.

Thanks!
Feb 11 '09 #1
3 1672
r035198x
13,262 8TB
No it's best done using PHP. If you think the way you constructed your PHP is not efficient then post your PHP code in the PHP forum so the PHP experts can have a look.
Feb 13 '09 #2
Atli
5,058 Expert 4TB
Yea, I would agree with r0.

You *could* probably do this using various tricks, but it would certainly not improve the efficiency of the application.

The simplest, and usually most efficient, ways to get these sort of datasets would be to either:
  1. Get a list of IDs from table a and then get a list of notes from table b individually for each ID.
    This would probably be more efficient if you have large datasets, where each ID has a large amount of notes.
  2. Get the entire list, where each note from table b is accompanied with the ID from table a.
    This would be better for smaller datasets, or in the case you have a lot of IDs with only a few notes each.
Either way, the actual sorting and the logic would be done in PHP.
Feb 13 '09 #3
blyxx86
256 100+
Thank you both for the answers.

I will post my code in the PHP section to see if it can be improved.
Feb 13 '09 #4

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

Similar topics

0
by: Glen | last post by:
I have a Struts action form which contains a bean. I am trying to display a bean retrieved from the database in this form using the nested tag. Can anyone help me? I continue to get an error...
6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
6
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
1
by: Tomas Sieger | last post by:
Hi all, I'm in doubt with the following code: class Base { public: class Nested {}; }; class Derived:public Base { public: class Nested {
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
7
by: patrick j | last post by:
Hi I'm wondering about lists with nested lists as one does on a Saturday afternoon. Anyway below is an example of a list with a nested list which the iCab browser's very useful HTML...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
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,...
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...

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.