473,587 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Dummy

jim
Hi,

I have two queries:

qReg:

SELECT tblRegionalExpe rience.Consulta ntID, tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
WHERE (((tblRegionalE xperience.Regio nID)=1));
qLang:

SELECT tblLanguageSkil ls.ConsultantID , tblLanguageSkil ls.LanguageID
FROM tblLanguageSkil ls
WHERE (((tblLanguageS kills.LanguageI D)=1));
i have these joined together in qAll:

SELECT qLang.Consultan tID, qLang.LanguageI D, qReg.Consultant ID,
qReg.RegionID
FROM qLang INNER JOIN qReg ON qLang.Consultan tID = qReg.Consultant ID;

but i would like be able to write qAll without reference to qReg or
qLang. my efforts so far have been hopeless any help much appreciated.
Oct 25 '06 #1
6 2051
You can use what we call derived tables - which are just sub queries -
as long as you have at least Access 2000.
qry a: Select a from x
qry b: Select b From y
qAll Select a,b From (Select a from x) as aliasA, (Select b From y) as
Aliasb

AliasA & AliasB are just a names I am giving the derived tables, call
them whatever you want as long as it is not already being used
somewhere in the qry. Rather than using the letter t prefix I use for
the tables, I use an a (eg. aCustomers)

There are a couple issues.
1) Once this is created "if" you go back into the sql of the qry,
access messes up the syntax for you and changes your () on the derived
tables to [] so you have to change them back.
2) Access doesn't like to have these as the recordsource for forms or
reports - you will have problems unless you save it as a qry and then
use the qry as the recordsource.
3) It's hellacious to debug your sql.

Other than that I use them all the time.

Good luck
Pachydermitis

SELECT aLang.Consultan tID, aLang.LanguageI D, aReg.Consultant ID,
aReg.RegionID
FROM (SELECT tblLanguageSkil ls.ConsultantID ,
tblLanguageSkil ls.LanguageID
FROM tblLanguageSkil ls
WHERE (((tblLanguageS kills.LanguageI D)=1))) as aLang INNER JOIN (SELECT
tblRegionalExpe rience.Consulta ntID, tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
WHERE (((tblRegionalE xperience.Regio nID)=1))) as aReg ON
aLang.Consultan tID = aReg.Consultant ID;
jim wrote:
Hi,

I have two queries:

qReg:

SELECT tblRegionalExpe rience.Consulta ntID, tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
WHERE (((tblRegionalE xperience.Regio nID)=1));
qLang:

SELECT tblLanguageSkil ls.ConsultantID , tblLanguageSkil ls.LanguageID
FROM tblLanguageSkil ls
WHERE (((tblLanguageS kills.LanguageI D)=1));
i have these joined together in qAll:

SELECT qLang.Consultan tID, qLang.LanguageI D, qReg.Consultant ID,
qReg.RegionID
FROM qLang INNER JOIN qReg ON qLang.Consultan tID = qReg.Consultant ID;

but i would like be able to write qAll without reference to qReg or
qLang. my efforts so far have been hopeless any help much appreciated.
Oct 25 '06 #2

jim wrote:
Hi,

I have two queries:

qReg:

SELECT tblRegionalExpe rience.Consulta ntID, tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
WHERE (((tblRegionalE xperience.Regio nID)=1));
qLang:

SELECT tblLanguageSkil ls.ConsultantID , tblLanguageSkil ls.LanguageID
FROM tblLanguageSkil ls
WHERE (((tblLanguageS kills.LanguageI D)=1));
i have these joined together in qAll:

SELECT qLang.Consultan tID, qLang.LanguageI D, qReg.Consultant ID,
qReg.RegionID
FROM qLang INNER JOIN qReg ON qLang.Consultan tID = qReg.Consultant ID;

but i would like be able to write qAll without reference to qReg or
qLang. my efforts so far have been hopeless any help much appreciated.
SELECT tblLanguageSkil ls.ConsultantID ,
tblLanguageSkil ls.LanguageID,
tblRegionalExpe rience.Consulta ntID,
tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
INNER JOIN tblLanguageSkil ls
ON tblRegionalExpe rience.Consulta ntID = tblLanguageSkil ls.ConsultantID
WHERE (tblRegionalExp erience.RegionI D=1) AND
(tblLanguageSki lls.LanguageID= 1)

should do what you want, but there's really no reason to include both
tblLanguageSkil ls.ConsultantID and tblRegionalExpe rience.Consulta ntID
since these should be equal because of your ON clause.

Bruce

Oct 25 '06 #3
Bruce,
your method could produce a large carteisan product based on the other
records in the table, and skew the results.

de************* **@gmail.com wrote:
jim wrote:
Hi,

I have two queries:

qReg:

SELECT tblRegionalExpe rience.Consulta ntID, tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
WHERE (((tblRegionalE xperience.Regio nID)=1));
qLang:

SELECT tblLanguageSkil ls.ConsultantID , tblLanguageSkil ls.LanguageID
FROM tblLanguageSkil ls
WHERE (((tblLanguageS kills.LanguageI D)=1));
i have these joined together in qAll:

SELECT qLang.Consultan tID, qLang.LanguageI D, qReg.Consultant ID,
qReg.RegionID
FROM qLang INNER JOIN qReg ON qLang.Consultan tID = qReg.Consultant ID;

but i would like be able to write qAll without reference to qReg or
qLang. my efforts so far have been hopeless any help much appreciated.

SELECT tblLanguageSkil ls.ConsultantID ,
tblLanguageSkil ls.LanguageID,
tblRegionalExpe rience.Consulta ntID,
tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
INNER JOIN tblLanguageSkil ls
ON tblRegionalExpe rience.Consulta ntID = tblLanguageSkil ls.ConsultantID
WHERE (tblRegionalExp erience.RegionI D=1) AND
(tblLanguageSki lls.LanguageID= 1)

should do what you want, but there's really no reason to include both
tblLanguageSkil ls.ConsultantID and tblRegionalExpe rience.Consulta ntID
since these should be equal because of your ON clause.

Bruce
Oct 25 '06 #4
jim
Thanks guys, have done some reading on sub queries and managed to make
some real progress with this, which i have been struggling with for over
a week.... many thanks for your input...

Pachydermitis wrote:
Bruce,
your method could produce a large carteisan product based on the other
records in the table, and skew the results.

de************* **@gmail.com wrote:
>jim wrote:
>>Hi,

I have two queries:

qReg:

SELECT tblRegionalExpe rience.Consulta ntID, tblRegionalExpe rience.RegionID
FROM tblRegionalExpe rience
WHERE (((tblRegionalE xperience.Regio nID)=1));
qLang:

SELECT tblLanguageSkil ls.ConsultantID , tblLanguageSkil ls.LanguageID
FROM tblLanguageSkil ls
WHERE (((tblLanguageS kills.LanguageI D)=1));
i have these joined together in qAll:

SELECT qLang.Consultan tID, qLang.LanguageI D, qReg.Consultant ID,
qReg.Region ID
FROM qLang INNER JOIN qReg ON qLang.Consultan tID = qReg.Consultant ID;

but i would like be able to write qAll without reference to qReg or
qLang. my efforts so far have been hopeless any help much appreciated.
SELECT tblLanguageSkil ls.ConsultantID ,
tblLanguageSki lls.LanguageID,
tblRegionalExp erience.Consult antID,
tblRegionalExp erience.RegionI D
FROM tblRegionalExpe rience
INNER JOIN tblLanguageSkil ls
ON tblRegionalExpe rience.Consulta ntID = tblLanguageSkil ls.ConsultantID
WHERE (tblRegionalExp erience.RegionI D=1) AND
(tblLanguageSk ills.LanguageID =1)

should do what you want, but there's really no reason to include both
tblLanguageSki lls.ConsultantI D and tblRegionalExpe rience.Consulta ntID
since these should be equal because of your ON clause.

Bruce
Oct 26 '06 #5

Pachydermitis wrote:
Bruce,
your method could produce a large carteisan product based on the other
records in the table, and skew the results.
A Cartesian product would be the result of a cross join, not an inner
join, in that a Cartesian product returns all rows from the right side
of a join for each row in the left side. I'm not seeing a situation in
which our two queries would produce different results. If the intent
is to return a set of consultants from a specified region with a
specified language skill then both queries do this. However, a simple
select without subqueries suffices for this task as best I can tell.
That being said, I'm always up for learning something new or being
shown the error of my ways. I really just don't see the necessity of
subqueries for this. I think we've simply reversed the order in which
we are retrieving our results. Your subqueries first filter each table
separately and then perform a join. I simply join first and then
filter. Please let me know if I am overlooking something. It wouldn't
be the first time :)

Bruce

Oct 26 '06 #6
Hi Bruce,
I hope that I did not offend you at all. Since we don't know all the
data in the tables and how it relates to other tables, I was answering
the question in a way that I was sure would not have any undesired
results.

You can also get an cartesian product if you are joining fields that
are not primary keys. for example:
Table1
id prod Cust Date
1 123 2 1/1/2001
2 456 2 1/1/2001
3 123 1 2/1/2001
4 123 2 2/1/2001

Table2
ID cust inv amt
22 1 555 5
23 2 666 10
24 2 777 5

SELECT Table1.Cust, Sum(Table2.amt) AS SumOfamt, count(prod) as
CountOfProd
FROM Table1 INNER JOIN Table2 ON Table1.Cust = Table2.cust
GROUP BY Table1.Cust;

the invoice total for cust 2 will be 45 when it should be 15 because we
need other joins or sub queries.

SELECT aTable1.cust AS Expr1, Sum(Table2.amt) AS SumOfamt,
Count(aTable1.p rod) AS CountOfprod
FROM (select cust, count(Table1.pr od) as prod FROM Table1 group by
cust) AS aTable1 INNER JOIN Table2 ON aTable1.cust = Table2.cust
GROUP BY aTable1.cust;

will give us the correct numbers.

Another time derived tables can be a life saver is when you have huge
recordsets that you are joining. Say you have two tables that have 5
million rows each. If you can limit each with a derived table, then
join the smaller sets, you can speed up your data pull quite a bit. 5
million won't fly in access, but on some of the more robust engines I
have run into that scenario.

That being said I also may be overlooking something, and love this
forum because of all the stuff I learn from it. :)

P

de************* **@gmail.com wrote:
Pachydermitis wrote:
Bruce,
your method could produce a large carteisan product based on the other
records in the table, and skew the results.

A Cartesian product would be the result of a cross join, not an inner
join, in that a Cartesian product returns all rows from the right side
of a join for each row in the left side. I'm not seeing a situation in
which our two queries would produce different results. If the intent
is to return a set of consultants from a specified region with a
specified language skill then both queries do this. However, a simple
select without subqueries suffices for this task as best I can tell.
That being said, I'm always up for learning something new or being
shown the error of my ways. I really just don't see the necessity of
subqueries for this. I think we've simply reversed the order in which
we are retrieving our results. Your subqueries first filter each table
separately and then perform a join. I simply join first and then
filter. Please let me know if I am overlooking something. It wouldn't
be the first time :)

Bruce
Nov 2 '06 #7

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

Similar topics

2
1794
by: Christian Giordano | last post by:
Hi guys, I've an hosting in media temple (appliance-server) with plesk 7.5.1. I'm trying to bring make a CMS I did in another server to work there. The issues is related the file uploading, in fact a dummy script like that: $newname="ciro.jpg"; $uploaddir="test_folder/"; copy($file, $uploaddir.$newname); unlink($file);
0
1296
by: Jonathan Fine | last post by:
I'd appreciate comments on what I'm doing. Please be kind, I'm a new kid on the block. Here's my application. I'm writing some test code. (I'm a recent convert to unit testing.)
2
5144
by: JohnnyOnTheSpot | last post by:
If I select from a table and, for example, group by the month or day to determine how much activity there is day to day or month to month, it will only return months and days with a record and leave out any month or day without any records making it apear at a glance that every day or month has activity which forces me or whoever to have to...
4
2912
by: wireless | last post by:
I've written code that dynamically builds an sql query based on various constraint possibilities. The problem is the code would have been very complex had I not come up with a dummy constraint as a kind of place holder in the statement. To avoid complex logic that determines if there was another constraint before any other constraint and...
1
1541
by: CSDunn | last post by:
Hello, I am working with a vb6 Windows application that runs on Tablet PC's. There are about five SQL Server 2000 databases that tie into the application. SQL Server MSDE runs on the tablets, and currently there is only one instance running. There are efforts underway to upgrade the application to a .NET SmartClient. One enhancement that...
1
2387
by: nek | last post by:
Greetings, We try to automate database creation via script which gets executed remotely for a number of servers. This works fine for most of the servers. However, it occasionally fails some of them for certain reasons (eg. authorization, communication down) and results in dummy entry in 'System Database Directory' as follows:
1
1455
by: markjcostello | last post by:
Hi, I have a service running on my machine that generates continuous stats in xml. I want to constantly reference an xslt file (using <?xml-stylesheet type="text/xsl" href="Test3.xsl"?>) within the xml that does not change the formatting of the xml in any way when i access the xml in a browser. This means that the xsl file will be a "dummy"...
15
3091
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
3
4234
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been little changed since. However, it works only with an obsolete version of Saxon (6.2.2 I think), and it has a number of small bugs; and I've at last got...
35
21517
by: erik gartz | last post by:
Hi. I'd like to be able to write a loop such as: for i in range(10): pass but without the i variable. The reason for this is I'm using pylint and it complains about the unused variable i. I can achieve the above with more lines of code like: i = 0 while (i != 10): i += 1 Is there a concise way to accomplish this without adding extra lines
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8340
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
7967
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
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.