473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Statement

Can you do a Select Statement within a Select Statement? I want to build a
query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.
Nov 18 '05 #1
10 2358
yes, it's called subqueries but this is not the forum for this. thy the ado
newsgroup

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Can you do a Select Statement within a Select Statement? I want to build
a
query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.

Nov 18 '05 #2
In Access you can view the SQL statement behind the query designer.

"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.

Nov 18 '05 #3
You want to create a "derived table" by using a select in the FROM
clause.

--
Scott
http://www.OdeToCode.com

On Thu, 22 Apr 2004 17:37:46 -0400, "John Smith"
<no*******@addr ess.com> wrote:
Can you do a Select Statement within a Select Statement? I want to build a
query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.


Nov 18 '05 #4
Or in the SELECT part :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:re******** *************** *********@4ax.c om...
You want to create a "derived table" by using a select in the FROM
clause.

--
Scott
http://www.OdeToCode.com

On Thu, 22 Apr 2004 17:37:46 -0400, "John Smith"
<no*******@addr ess.com> wrote:
Can you do a Select Statement within a Select Statement? I want to build aquery similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.

Nov 18 '05 #5
Hi John,

What database are you talking about?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.

Nov 18 '05 #6
I am currently using Access, but if I migrated to another db I would like to
be able to easily take my queries with me in one big sql statement if
possible. I do know about the SQL View within Access, but I was wondering
for future use and for knowledge if it is possible to have queries within
queries, but only using the sql statement of the queries.

Maybe something like : Select tblOne.ID, [Select Count(tblTwo.Se condaryID)
FROM tblTwo WHERE tblTwo.Secondar yID = tblOne.ID], [Select
Count(tblTwo.An otherID) FROM tblTwo WHERE tblTwo.Secondar yID = tblOne.ID]
From tblOne.ID

I have no idea how to do this or if it is even possible or if the above is
even correct, so I thought that I would check here. I apologize for not
using the ADO.NET newgroups and I thank you for the responses I have already
received. If anybody could just give me some examples or some hints or
websites to check out I would definitely appreciate the help.

Thanx a lot for your help.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OV******** ******@TK2MSFTN GP11.phx.gbl...
Hi John,

What database are you talking about?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Can you do a Select Statement within a Select Statement? I want to
build a
query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.


Nov 18 '05 #7
"Derived Tables" Thanx Scott Allen
"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but
using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.

Nov 18 '05 #8
Hi John,

Yes, of course it is possible.
Use normal brackets () instead of square ones and make sure that select
returns only one record.
But I guess it really depends on database if it supports the notation
(Access 2003, Sql server 2000 and Oracle 9ir2 do).
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"John Smith" <no*******@addr ess.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
I am currently using Access, but if I migrated to another db I would like to be able to easily take my queries with me in one big sql statement if
possible. I do know about the SQL View within Access, but I was wondering
for future use and for knowledge if it is possible to have queries within
queries, but only using the sql statement of the queries.

Maybe something like : Select tblOne.ID, [Select Count(tblTwo.Se condaryID)
FROM tblTwo WHERE tblTwo.Secondar yID = tblOne.ID], [Select
Count(tblTwo.An otherID) FROM tblTwo WHERE tblTwo.Secondar yID = tblOne.ID]
From tblOne.ID

I have no idea how to do this or if it is even possible or if the above is
even correct, so I thought that I would check here. I apologize for not
using the ADO.NET newgroups and I thank you for the responses I have already received. If anybody could just give me some examples or some hints or
websites to check out I would definitely appreciate the help.

Thanx a lot for your help.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OV******** ******@TK2MSFTN GP11.phx.gbl...
Hi John,

What database are you talking about?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
Can you do a Select Statement within a Select Statement? I want to

build
a
query similar to queries built in Access which link to other queries but using only SQL Statements. Is it possible? If so, how do you do it?

Thanx in adv.



Nov 18 '05 #9
Thanx a lot for all the help. It works perfectly.

Okay, so let me ask you one more question now (last question, I promise
;) ). Can I connect to another database through the derived table method
using SQL for Access 2000? If so, how would I go about adding a new db
connection string into the SQL Statement? Both databases are in Access
2000.

SELECT TableOne.Field1 , (SELECT TableTwo.Field2 FROM TableTwo WHERE
TableTwo.Field1 = TableOne.Field1 ) AS FieldDescriptio n FROM TableOne
WHERE....
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
Hi John,

Yes, of course it is possible.
Use normal brackets () instead of square ones and make sure that select
returns only one record.
But I guess it really depends on database if it supports the notation
(Access 2003, Sql server 2000 and Oracle 9ir2 do).
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"John Smith" <no*******@addr ess.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
I am currently using Access, but if I migrated to another db I would like
to
be able to easily take my queries with me in one big sql statement if
possible. I do know about the SQL View within Access, but I was wondering for future use and for knowledge if it is possible to have queries within queries, but only using the sql statement of the queries.

Maybe something like : Select tblOne.ID, [Select Count(tblTwo.Se condaryID) FROM tblTwo WHERE tblTwo.Secondar yID = tblOne.ID], [Select
Count(tblTwo.An otherID) FROM tblTwo WHERE tblTwo.Secondar yID = tblOne.ID] From tblOne.ID

I have no idea how to do this or if it is even possible or if the above is even correct, so I thought that I would check here. I apologize for not
using the ADO.NET newgroups and I thank you for the responses I have

already
received. If anybody could just give me some examples or some hints or
websites to check out I would definitely appreciate the help.

Thanx a lot for your help.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:OV******** ******@TK2MSFTN GP11.phx.gbl...
Hi John,

What database are you talking about?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development miha at rthand com
www.rthand.com

"John Smith" <no*******@addr ess.com> wrote in message
news:uu******** ********@TK2MSF TNGP10.phx.gbl. ..
> Can you do a Select Statement within a Select Statement? I want to

build
a
> query similar to queries built in Access which link to other queries

but > using only SQL Statements. Is it possible? If so, how do you do it? >
> Thanx in adv.
>
>



Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2549
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
18
2699
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html In this post, I'm especially soliciting review of Carl Banks's point (now discussed under Open Issues)...
28
2927
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions! PEP: 359 Title: The "make" Statement Version: $Revision: 45366 $ Last-Modified: $Date: 2006-04-13 07:36:24 -0600 (Thu, 13 Apr 2006) $
7
2684
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
18
7949
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp defintion of "expression" and "statement"? What is the difference between an expression and a statement?
0
7804
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.