It's been a loooong time since I've worked with Access. I want to be able to do queries on 'Class'.
My 'Class' table:
Fields: Class, Element 1, Element 2, Element 3
Data: Class A, Red, Maroon, Cerise
Class B, Violet, Mauve, Purple
Class C, Emerald, Forest, Lime
My 'Rooms' table:
Fields: Room, Colours
Data Room 1, Purple Red Violet Lime
Room 2, Maroon Forest Cerise
I want to query by Class such that if I query on Class B, it will give me Room 1 in the results (because Room 1 has Purple in it which is in Class B).
In the end I will have many rooms, each with many colours but because the colours belong to classes, I want to be able to query on the class rather than constructing lengthy queries for all the colours in a class.
Question 1: In the 'Rooms' table, can I use a single 'colours' field and enter many colours in it (each would have a different class) or must I create many 'colours' fields?
Question 2: how do I structure the tables such that this query will work?
(I think I used to know this but it was ages ago).
Thanks much.
6 1250 nico5038 3,080
Recognized Expert Specialist
To get correct normalized tables you'll need to use just one Element in a table like: - Class A, Red
-
Class A, Maroon
-
Class A, Cerise
-
Class B, Violet
-
Class B, Mauve
-
Class B, Purple
-
etc.
Having this setup you can join to the other table by the colorfield.
The present setup would require a union like: - select class,element1 from tblClass
-
UNION
-
select class,element2 from tblClass
-
UNION
-
select class,element3 from tblClass;
This will deliver the normalized data and then the query could be used to join by element to the other table.
Getting the idea ?
Nic;o)
Ah yes! 'Normalization' - it's arising from the foggy mists of memory. That's what's wanted! I'll give that a try. Thanks!
nico5038 3,080
Recognized Expert Specialist
Just keep me posted about the progress :-)
Nic;o)
NeoPa 32,556
Recognized Expert Moderator MVP
************ Misunderstanding - Please Ignore **********
I've just reread Nico's post and realised I'd got the wrong end of the stick. He was actually talking about how to convert the present data into the correctly designed table layout. In this case he was absolutely correct and I should have guessed :(
************************************************** ***********
- select class,element1 from tblClass
-
UNION
-
select class,element2 from tblClass
-
UNION
-
select class,element3 from tblClass;
It's a minor detail but, to avoid confusion, the second field of the SELECT clause should be the same in all cases as they refer to the same field in the same table.
So, the SQL should be like : - select class,element from tblClass
-
UNION
-
select class,element from tblClass
-
UNION
-
select class,element from tblClass;
HTH.
nico5038 3,080
Recognized Expert Specialist
Hi, NeoPa.
Sorry to correct you, but all a UNION requires is the same number of columns and the same datatype.
The Element1, Element2, etc can be in separate rows, as long as they are all text, number or date. The result will however use the fieldnames of the first select, so to get just Element, use for the first:
select Class, Element1 as Element from tblX
The other selects won't change the name the query returns.
Nic;o)
NeoPa 32,556
Recognized Expert Moderator MVP
You're absolutely right Nico (and apology not necessary even if you had not been).
However, that wasn't my confusion - I was further off base than that even :( I got completely the wrong end of the stick.
I was thinking you were running the UNION query on the data that actually you were producing. A two column table - hence my post. I was aware of the point you make here (but it never hurts for it to be expressed publicly).
Preferably I would have deleted the post completely but contributors would likely be confused if they'd had an email just to find a gap where the post had been.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: QWERTY |
last post by:
--------------Boundary-00=_O5I3QL80000000000000
Content-Type: Multipart/Alternative;
boundary="------------Boundary-00=_O5I3LVC0000000000000"
--------------Boundary-00=_O5I3LVC0000000000000...
|
by: Muhammad Farooq-i-Azam |
last post by:
Hi,
I am trying to define an arp structure but having problem
doing so. I think I have define the correct arp structure but
I find myself in a strange problem. The size of structure that
I have...
|
by: ranjeet.gupta |
last post by:
Dear All !!
Before i qoute my querry, I will like to qoute my analysis and my
Knowledge
Struct a {
int raw;
char data;
};
|
by: Brett |
last post by:
I have created a structure with five fields. I then create an array of this
type of structure and place the structure into an array element. Say index
one. I want to assign a value to field3 of...
|
by: JC Voon |
last post by:
Hi All:
I have a problem when trying to set the value of the structure member
using reflaction,here is the code:
Public Const MemberAccess As BindingFlags = BindingFlags.Public Or...
| |
by: nambissan.nisha |
last post by:
I am facing this problem....
I have to define a structure at runtime as the user specifies...
The user will tell the number of fields,the actual fields...(maybe
basic or array types or...
|
by: sameerishah |
last post by:
Hi,
I have a need to read the fields of a structure in a for loop.
for eg. the structure looks like:
str.a1, str.a2, str.a3 where a1, a2, a3 are of type string
How do I do it?
Thanks in...
|
by: pkoniusz |
last post by:
Hello everybody,
Been just thinking how actually one could convert the following
unmanaged code to the managed C++:
struct JustAnExample
{
char value1;
int value2;
// etc ....
|
by: p.lavarre |
last post by:
How do I vary the byte offset of a field of a ctypes.Structure?
How do I "use the dynamic nature of Python, and (re-)define the data
type after the required size is already known, on a case by...
|
by: eBob.com |
last post by:
In my class which contains the code for my worker thread I have ...
Public MustInherit Class Base_Miner
#Region " Delegates for accessing main UI form "
Delegate Sub DelegAddProgressBar(ByVal...
|
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,...
| |
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...
|
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: 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,...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |