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

Problems writing a linked query in SQL

Hello Newsgroup,

I am doing some archive database and therefore got one table indexing
every folder and one table storing which rack belongs to which
department, eg:
table folders :
+-----------+------+-------+
| folder_id | rack | date |
+===========+======+=======+
| 123456789 | 325 | 05/02 |
+-----------+------+-------+
| 987654321 | 158 | 02/07 |
+-----------+------+-------+
| 987485221 | 666 | 01/05 |
+-----------+------+-------+
table racks:
+----+------+------------+
| id | rack | department |
+====+======+============+
| 1 | 158 | FKA/PKG |
+----+------+------------+
| 2 | 555 | KOV/GDA |
+----+------+------------+
| 3 | 666 | FKA/PKG |
+----+------+------------+
| 4 | 123 | ORG/RET |
+----+------+------------+
Now I have to select all the folders which have for example an equal
date belonging to a certain department, meaning:
- I have to find the racks belonging to eg "FKA/PGK" (158, 666)
- Then I'll got to find every folder belonging to the racks 666 and
158 (987485221, 987654321)
- Then I've got to find those which belong to a certain condition
(eg.
date <02/2001)
Sure I could do that in three queries, but somehow I've got the
feeling that SQL is powerfull enough to do this in one query.
But how?
thanks in advance
Thorben Grosser

Jul 30 '07 #1
3 2614
select r.rack, f.folder_id
from folders as f
inner join racks as r on f.rack = r.rack
where r.department = 'FKA/PGK'
and f.[date] < #02/01/2001#

Thorben Grosser wrote:
Hello Newsgroup,

I am doing some archive database and therefore got one table indexing
every folder and one table storing which rack belongs to which
department, eg:
table folders :
+-----------+------+-------+
| folder_id | rack | date |
+===========+======+=======+
| 123456789 | 325 | 05/02 |
+-----------+------+-------+
| 987654321 | 158 | 02/07 |
+-----------+------+-------+
| 987485221 | 666 | 01/05 |
+-----------+------+-------+
table racks:
+----+------+------------+
| id | rack | department |
+====+======+============+
| 1 | 158 | FKA/PKG |
+----+------+------------+
| 2 | 555 | KOV/GDA |
+----+------+------------+
| 3 | 666 | FKA/PKG |
+----+------+------------+
| 4 | 123 | ORG/RET |
+----+------+------------+
Now I have to select all the folders which have for example an equal
date belonging to a certain department, meaning:
- I have to find the racks belonging to eg "FKA/PGK" (158, 666)
- Then I'll got to find every folder belonging to the racks 666 and
158 (987485221, 987654321)
- Then I've got to find those which belong to a certain condition
(eg.
date <02/2001)
Sure I could do that in three queries, but somehow I've got the
feeling that SQL is powerfull enough to do this in one query.
But how?
thanks in advance
Thorben Grosser
Jul 30 '07 #2
As a start, I'd comment that "date" should not be used as a Field Name
because it is an Access reserved word and can lead to confusion, and that
"05/02" is not a date, in any case, but a code for expressing (presumably)
month and year, or perhaps year and month (not obvious from your data,
though your description of the coimparison, later, leads me to suspect it is
month/year).

The 'date' field should be renamed to something unique like "FolderDate" --
it can either can be handled in the query to compare the year and month, or
the file can be processed with an update query to convert it to a date.
And, also, I am not sure when you use <02/2001, whether you mean "newer than
February 2001" or "older than February 2001."

Finally, numbers used for identification, such as your Folder ID and Rack,
are often stored as alpha characters... it's not unusual, in a list of
"racks" or such, to find a few later additions like "158A" and "158B" or
"U666". In this example, that shouldn't make a difference, because no
criteria is applied to either of those Fields.

You also need to clarify what you want to happen if there is a folder
specifying a rack number that is not in the 'racks' table. That will
influence the type of join you use in the Query. My suggestion would be to
show it without a department in a specific query used for exception
reporting, because it probably indicates either a mistake in data entry, or
a rack that has not yet been added to the 'racks' table.

Your use of lowercase for table and fieldnames leads me to think that you
are new to Access, and possibly not familiar with the Query Builder. If you
are writing Access SQL without taking advantage of the Query Builder, you
are doing yourself a disservice.

Once you clarify the points above, the solution to your problem should not
be difficult -- an expression to construct an actual date from the "date"
field, and a Query, relatively easy to create in the Query Builder (or in
SQL for that matter).

Larry Linson
Microsoft Access MVP

"Thorben Grosser" <th*************@gmail.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
Hello Newsgroup,

I am doing some archive database and therefore got one table indexing
every folder and one table storing which rack belongs to which
department, eg:
table folders :
+-----------+------+-------+
| folder_id | rack | date |
+===========+======+=======+
| 123456789 | 325 | 05/02 |
+-----------+------+-------+
| 987654321 | 158 | 02/07 |
+-----------+------+-------+
| 987485221 | 666 | 01/05 |
+-----------+------+-------+
table racks:
+----+------+------------+
| id | rack | department |
+====+======+============+
| 1 | 158 | FKA/PKG |
+----+------+------------+
| 2 | 555 | KOV/GDA |
+----+------+------------+
| 3 | 666 | FKA/PKG |
+----+------+------------+
| 4 | 123 | ORG/RET |
+----+------+------------+
Now I have to select all the folders which have for example an equal
date belonging to a certain department, meaning:
- I have to find the racks belonging to eg "FKA/PGK" (158, 666)
- Then I'll got to find every folder belonging to the racks 666 and
158 (987485221, 987654321)
- Then I've got to find those which belong to a certain condition
(eg.
date <02/2001)
Sure I could do that in three queries, but somehow I've got the
feeling that SQL is powerfull enough to do this in one query.
But how?
thanks in advance
Thorben Grosser


Jul 30 '07 #3
Hy Larry,

many thanks first for yourvery helpfull answer

On 31 Jul., 00:20, "Larry Linson" <boun...@localhost.notwrote:
And, also, I am not sure when you use <02/2001, whether you mean "newer than
February 2001" or "older than February 2001."
I'd like to apolgize for the confusion caused by my post. Both tables
are but examples and don't show the final design nor the names of the
tables, its just for the general understanding. Speaking about the
older/newer confusion, I acutally had a similar problem when comparing
dates as I didn't know how Access (and VBA) sees things. Trial and
error helped.
You also need to clarify what you want to happen if there is a folder
specifying a rack number that is not in the 'racks' table. That will
influence the type of join you use in the Query. My suggestion would be to
show it without a department in a specific query used for exception
reporting, because it probably indicates either a mistake in data entry, or
a rack that has not yet been added to the 'racks' table.
I totally agree with you. I think that should be fine.
Your use of lowercase for table and fieldnames leads me to think that you
are new to Access, and possibly not familiar with the Query Builder. If you
are writing Access SQL without taking advantage of the Query Builder, you
are doing yourself a disservice.
I am quite amazed by the fact that one can recon one others Access
skills by checking the upper/lower case writing.
Indeed, I never considered the query builder as something usual (I am
quite used to PHP and MySQL where you usually dont have that luxury),
but it seems as I should take a deeper look,

thanks a lot,
and have a nice day
Thorben Grosser

Jul 31 '07 #4

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

Similar topics

2
by: James Allan | last post by:
Hello -- I'm trying to get SQL Server 2000 on a Windows 2000 Server to be able to query an Active Directory. We've got two domain servers one Win2000 and one Win2003. However, I'm having...
1
by: A.M. de Jong | last post by:
When I perform a query on a linked Oracle server in the Query analyser I have no prboblem' to perform this query. However, when I create this query in a stored procedure I get a compilation error...
9
by: JMCN | last post by:
hi- i have inherited an access 97 database that keeps track of the loans. i have been running into referential intergrity problems when i try to append new loans to table. first of all is a...
2
by: neptune | last post by:
I currently link a table to an Oracle db. Anytime I open a query based off it, I have to input username & password. Is there a way to do this automatically? I'd prefer to use linked tables,...
7
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
3
by: Zlatko Matić | last post by:
Hi! What happens with linked tables if they were linked using File DSN, when I copy the Access file on some other PC without File DSN ? What is the difference between DSN on linked tables and...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
24
by: tanmay | last post by:
please tell me how to get the following output using loops... 1) * * * * * * * * * * * * * * * *
11
by: jjkeeper | last post by:
Hi, I need to create an annual leave Database for the company. I admit I was a complete novice at this. But I got thrown the job and I have to do it. So here's what I get so far, but I got pretty...
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:
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
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,...
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...
0
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...

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.