473,770 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with query need

Any suggestions for the following would be gratefully accepted.

I have a table which includes name and interest fields e.g.,

contact interest
smith carpentry
jones gardening
smith plumbing
smith geology
jones geology

I want users to be able to produce a report which lists the names of those
who meet certain criteria (i.e., the user selects up to 3 interests using
combo boxes and then produces a report which lists the names of those who
have those interests). For example, choosing geology and carpentry should
return only the name 'smith'.

Nov 13 '05 #1
2 1449
news.uow.edu.au wrote:
Any suggestions for the following would be gratefully accepted.

I have a table which includes name and interest fields e.g.,

contact interest
smith carpentry
jones gardening
smith plumbing
smith geology
jones geology

I want users to be able to produce a report which lists the names of those
who meet certain criteria (i.e., the user selects up to 3 interests using
combo boxes and then produces a report which lists the names of those who
have those interests). For example, choosing geology and carpentry should
return only the name 'smith'.

You would be much better off to have the names listed once in a single
table the interests in a second table listed once and a third table
which has a pointer number from the first and second.

For example:

TBL_CONTACTS

CON_PK CON_NAME_2 CON_NAME_1 CON_ADDRESS etc, etc
7568 Smith John
123 Jones Brigitte
34569 Keen I.M.
etc

TBL_INTERESTS

INT_PK INT_DESCRIP INT_DETAILS etc, etc
671234 Carpentry Hitting things with hammers...
1235 Gardening Swearing at and hitting weeds with hammers...
1112 Plumbing Hitting pipes with hammers...
98356 Geology Hitting rocks with hammers....

TBL_INTEREST_LO OKUP (configured as for your example)

LU_CON_FK LU_INT_FK
7568 671234
123 1235
7568 1112
7568 98356
123 98356

For the PK numbers, you never let people see or bother with the numbers
- use an autonumber datatype (that's why I stuffed in random looking
numbers).

This is a harder way to do things for a newbie, especially with respect
to data entry - you'll need to make up 3 forms: one for listing and
adding/editing contacts (form associated with TBL_CONTACTS), another for
listing interests (form associated with TBL_INTERESTS) and a third,
probably using combo boxes, to list contacts and interests.

Hard, yes, but you'll thank yourself in the future for doing things the
database way.

The query to get the information you'd want would be (air code):

select
CON_NAME_1 & ", " & CON_NAME_2 as Contact,
INT_DESCRIP as Interest
from
(TBL_INTERESTS INNER JOIN TBL_INTEREST_LO OKUP ON TBL_INTEREST.IN T_PK =
TBL_INTEREST_LO OKUP.LU_INT_FK) INNER JOIN TBL_CONTACTS ON
TBL_INTEREST_LO OKUP.LU_CON_FK = TBL_CONTACTS.CO N_PK
where
INT_DESCRIP like Forms!MyForm.cb oInterest1 & "*" or
INT_DESCRIP like Forms!MyForm.cb oInterest2 & "*" or
INT_DESCRIP like Forms!MyForm.cb oInterest3 & "*"

Open a query, close the show table dialog and click on the SQL view of
the table and paste the above into the query.

The key part here (which can be used also on your single table approach
in your original post) is the where clause, above. By using the Like
operator, you allow a combo box which has nothing in it to not mess up
the works.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #2

"Tim Marshall" <TI****@PurpleP andaChasers.Moe rtherium> wrote in message
news:d5******** **@coranto.ucs. mun.ca...
news.uow.edu.au wrote:
Any suggestions for the following would be gratefully accepted.

I have a table which includes name and interest fields e.g.,

contact interest
smith carpentry
jones gardening
smith plumbing
smith geology
jones geology

I want users to be able to produce a report which lists the names of
those who meet certain criteria (i.e., the user selects up to 3 interests
using combo boxes and then produces a report which lists the names of
those who have those interests). For example, choosing geology and
carpentry should return only the name 'smith'.

You would be much better off to have the names listed once in a single
table the interests in a second table listed once and a third table which
has a pointer number from the first and second.

For example:

TBL_CONTACTS

CON_PK CON_NAME_2 CON_NAME_1 CON_ADDRESS etc, etc
7568 Smith John
123 Jones Brigitte
34569 Keen I.M.
etc

TBL_INTERESTS

INT_PK INT_DESCRIP INT_DETAILS etc, etc
671234 Carpentry Hitting things with hammers...
1235 Gardening Swearing at and hitting weeds with hammers...
1112 Plumbing Hitting pipes with hammers...
98356 Geology Hitting rocks with hammers....

TBL_INTEREST_LO OKUP (configured as for your example)

LU_CON_FK LU_INT_FK
7568 671234
123 1235
7568 1112
7568 98356
123 98356

For the PK numbers, you never let people see or bother with the numbers -
use an autonumber datatype (that's why I stuffed in random looking
numbers).

This is a harder way to do things for a newbie, especially with respect to
data entry - you'll need to make up 3 forms: one for listing and
adding/editing contacts (form associated with TBL_CONTACTS), another for
listing interests (form associated with TBL_INTERESTS) and a third,
probably using combo boxes, to list contacts and interests.

Hard, yes, but you'll thank yourself in the future for doing things the
database way.

The query to get the information you'd want would be (air code):

select
CON_NAME_1 & ", " & CON_NAME_2 as Contact,
INT_DESCRIP as Interest
from
(TBL_INTERESTS INNER JOIN TBL_INTEREST_LO OKUP ON TBL_INTEREST.IN T_PK =
TBL_INTEREST_LO OKUP.LU_INT_FK) INNER JOIN TBL_CONTACTS ON
TBL_INTEREST_LO OKUP.LU_CON_FK = TBL_CONTACTS.CO N_PK
where
INT_DESCRIP like Forms!MyForm.cb oInterest1 & "*" or
INT_DESCRIP like Forms!MyForm.cb oInterest2 & "*" or
INT_DESCRIP like Forms!MyForm.cb oInterest3 & "*"

Open a query, close the show table dialog and click on the SQL view of the
table and paste the above into the query.

The key part here (which can be used also on your single table approach in
your original post) is the where clause, above. By using the Like
operator, you allow a combo box which has nothing in it to not mess up the
works.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me


Thanks Tim,

much appreciate the response, it gets me half of what I'd like, but i'm
still stuck on the rest e.g., if i search for people who have 3 interests,
I get them, but I also get the names of those who have only 1 or 2 of the
three. I'd like to be able to return ONLY the names of those who have ALL
the interests (i.e., to exclude those who have only 1 or 2 of the interests.

PS: I thought i might be able to use the COUNT option to limit the result to
those who have all 3 interests only, but it all seems a bit beyond my skills
:-(
Nov 13 '05 #3

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

Similar topics

9
3137
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
7
31564
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
9
4354
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
8
19600
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
5
2147
by: Rated R1 | last post by:
I wrote this before in the NGs, so I am going to paste the responses that I got and see if someone can please help me. Email me and we can set something up as Id even be willing to pay for your time to get me to learn this procedure: MY ORIGINAL POST: I am trying to create a database for my small business. I have typed a bunch of information in a table in 5 columns (style, mm, karat, quantity, labor cost). We have different labor...
5
2200
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table, all has gone very well with one exception. The table is based on applications made by potential customers looking to buy franchise rights to particular locations and as part of the process they are asked to list their preferred locations 1 to 4....
4
2281
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5 companies on a form. 3 of the companies have common employees. I have a table that looks like this:
10
2593
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only tool you know how to use is a hammer, every problem tends to look like a nail. That said, I could solve my problem in C, but it's not the right tool. I need to come into the Windows world, and I need to get this done in Access or something...
8
2087
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a web form when one presses the button on the web form on a client pc, the sql query which is contained in the text box is sent to a vb net application on a server pc. The win application sends the query to the database, collects the results,
11
319
by: troy_lee | last post by:
I have two fields on a form. These two fields' values are based on an expression and represent a date range. I need to create a SQL statement that will use the returned values of these two fields in the WHERE clause as a date range (less than or equal to, and greater than or equal to the upper and lower dates of the range). I then need to count the total number of records returned from the query and output the record count to another...
0
9618
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7456
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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

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.