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

SQL subquery problem - bookings database

Hi,

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking
system for these camps.

My tables are setup as:

- people_people which contains name / address details for the volunteers.
Primary key is id field.

- camps_info which contains information on each camp. Primary key is
camp_number field.

- camps_bookings. This has a record for each booking made.

I want a query which will give me a list of each camp (ie corresponding to
each record in camps_info) and alongside that display the number of bookings
there are for each camp.

I have successfully set up a parameter query that will tell me the number of
bookings for a particular camp:

SELECT sum(camps_info.camp_number) AS num_bookings_on_this_camp

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

WHERE (((camps_info.camp_number)=[What camp number?]));

However, rather than typing in each camp number, I want the query to do the
number of bookings for each camp number in the camps_info table.

I imagine that I need a sub-query for this? I have been trying various
things
(http://www.experts-exchange.com/Data...r/Q_20863705.h
tml is the most useful page I've found so far). things I have tried are:

select o.*, s.*

from camps_info o,

(

SELECT sum(camps_info.camp_number), camp_number

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

) s

where o.camp_number = s.camp_number

;

...which gives an error "The specified field 'camp_number' could refer to
more than one table listed in the FROM clause of your SQL statement"

I also tried:

Select c1.camp_number, num_bookings_on_this_camp

from camps_info c1, camps_info c2, (

SELECT sum(c2.camp_number) AS num_bookings_on_this_camp

FROM c2 INNER JOIN camps_bookings ON c2.camp_number =
camps_bookings.camp_number

)

WHERE (c2.camp_number=c1.camp_number)

;

..which gives the error "The Microsoft Jet database engine cannot find the
input table of query 'c2'. Make sure it exists and that its name is spelled
correctly".

Another thing I thought of was to somehow set up a function
NumberOfBookings(CampNumber) via an Access VBA module that ran my first
query for each camp. However, I haven't had much success with this, and
logic tells me there must be a way of doing this within SQL alone.

Does anyone have any tips on the SQL statement I should be using for my
query?

Very many thanks.

--Dan Evans.

dd*****@hotmail.com
Jul 19 '05 #1
6 1716
I think you can change your WHERE .. statement to GROUP BY o.camp_number

Dan Evans wrote:
Hi,

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking
system for these camps.

My tables are setup as:

- people_people which contains name / address details for the volunteers.
Primary key is id field.

- camps_info which contains information on each camp. Primary key is
camp_number field.

- camps_bookings. This has a record for each booking made.

I want a query which will give me a list of each camp (ie corresponding to
each record in camps_info) and alongside that display the number of bookings
there are for each camp.

I have successfully set up a parameter query that will tell me the number of
bookings for a particular camp:

SELECT sum(camps_info.camp_number) AS num_bookings_on_this_camp

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

WHERE (((camps_info.camp_number)=[What camp number?]));

However, rather than typing in each camp number, I want the query to do the
number of bookings for each camp number in the camps_info table.

I imagine that I need a sub-query for this? I have been trying various
things
(http://www.experts-exchange.com/Data...r/Q_20863705.h
tml is the most useful page I've found so far). things I have tried are:

select o.*, s.*

from camps_info o,

(

SELECT sum(camps_info.camp_number), camp_number

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

) s

where o.camp_number = s.camp_number

;

..which gives an error "The specified field 'camp_number' could refer to
more than one table listed in the FROM clause of your SQL statement"

I also tried:

Select c1.camp_number, num_bookings_on_this_camp

from camps_info c1, camps_info c2, (

SELECT sum(c2.camp_number) AS num_bookings_on_this_camp

FROM c2 INNER JOIN camps_bookings ON c2.camp_number =
camps_bookings.camp_number

)

WHERE (c2.camp_number=c1.camp_number)

;

.which gives the error "The Microsoft Jet database engine cannot find the
input table of query 'c2'. Make sure it exists and that its name is spelled
correctly".

Another thing I thought of was to somehow set up a function
NumberOfBookings(CampNumber) via an Access VBA module that ran my first
query for each camp. However, I haven't had much success with this, and
logic tells me there must be a way of doing this within SQL alone.

Does anyone have any tips on the SQL statement I should be using for my
query?

Very many thanks.

--Dan Evans.

dd*****@hotmail.com

Jul 19 '05 #2
I think you can change your WHERE .. statement to GROUP BY o.camp_number

Dan Evans wrote:
Hi,

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking
system for these camps.

My tables are setup as:

- people_people which contains name / address details for the volunteers.
Primary key is id field.

- camps_info which contains information on each camp. Primary key is
camp_number field.

- camps_bookings. This has a record for each booking made.

I want a query which will give me a list of each camp (ie corresponding to
each record in camps_info) and alongside that display the number of bookings
there are for each camp.

I have successfully set up a parameter query that will tell me the number of
bookings for a particular camp:

SELECT sum(camps_info.camp_number) AS num_bookings_on_this_camp

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

WHERE (((camps_info.camp_number)=[What camp number?]));

However, rather than typing in each camp number, I want the query to do the
number of bookings for each camp number in the camps_info table.

I imagine that I need a sub-query for this? I have been trying various
things
(http://www.experts-exchange.com/Data...r/Q_20863705.h
tml is the most useful page I've found so far). things I have tried are:

select o.*, s.*

from camps_info o,

(

SELECT sum(camps_info.camp_number), camp_number

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

) s

where o.camp_number = s.camp_number

;

..which gives an error "The specified field 'camp_number' could refer to
more than one table listed in the FROM clause of your SQL statement"

I also tried:

Select c1.camp_number, num_bookings_on_this_camp

from camps_info c1, camps_info c2, (

SELECT sum(c2.camp_number) AS num_bookings_on_this_camp

FROM c2 INNER JOIN camps_bookings ON c2.camp_number =
camps_bookings.camp_number

)

WHERE (c2.camp_number=c1.camp_number)

;

.which gives the error "The Microsoft Jet database engine cannot find the
input table of query 'c2'. Make sure it exists and that its name is spelled
correctly".

Another thing I thought of was to somehow set up a function
NumberOfBookings(CampNumber) via an Access VBA module that ran my first
query for each camp. However, I haven't had much success with this, and
logic tells me there must be a way of doing this within SQL alone.

Does anyone have any tips on the SQL statement I should be using for my
query?

Very many thanks.

--Dan Evans.

dd*****@hotmail.com

Jul 19 '05 #3
I think you can change your WHERE .. statement to GROUP BY o.camp_number

Dan Evans wrote:
Hi,

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking
system for these camps.

My tables are setup as:

- people_people which contains name / address details for the volunteers.
Primary key is id field.

- camps_info which contains information on each camp. Primary key is
camp_number field.

- camps_bookings. This has a record for each booking made.

I want a query which will give me a list of each camp (ie corresponding to
each record in camps_info) and alongside that display the number of bookings
there are for each camp.

I have successfully set up a parameter query that will tell me the number of
bookings for a particular camp:

SELECT sum(camps_info.camp_number) AS num_bookings_on_this_camp

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

WHERE (((camps_info.camp_number)=[What camp number?]));

However, rather than typing in each camp number, I want the query to do the
number of bookings for each camp number in the camps_info table.

I imagine that I need a sub-query for this? I have been trying various
things
(http://www.experts-exchange.com/Data...r/Q_20863705.h
tml is the most useful page I've found so far). things I have tried are:

select o.*, s.*

from camps_info o,

(

SELECT sum(camps_info.camp_number), camp_number

FROM camps_info INNER JOIN camps_bookings ON camps_info.camp_number =
camps_bookings.camp_number

) s

where o.camp_number = s.camp_number

;

..which gives an error "The specified field 'camp_number' could refer to
more than one table listed in the FROM clause of your SQL statement"

I also tried:

Select c1.camp_number, num_bookings_on_this_camp

from camps_info c1, camps_info c2, (

SELECT sum(c2.camp_number) AS num_bookings_on_this_camp

FROM c2 INNER JOIN camps_bookings ON c2.camp_number =
camps_bookings.camp_number

)

WHERE (c2.camp_number=c1.camp_number)

;

.which gives the error "The Microsoft Jet database engine cannot find the
input table of query 'c2'. Make sure it exists and that its name is spelled
correctly".

Another thing I thought of was to somehow set up a function
NumberOfBookings(CampNumber) via an Access VBA module that ran my first
query for each camp. However, I haven't had much success with this, and
logic tells me there must be a way of doing this within SQL alone.

Does anyone have any tips on the SQL statement I should be using for my
query?

Very many thanks.

--Dan Evans.

dd*****@hotmail.com

Jul 19 '05 #4

"Dan Evans" <dd*****@hotmail.com> wrote in message
news:40***********************@mercury.nildram.net ...

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking system for these camps.


news://comp.database.ms-access
Jul 19 '05 #5

"Dan Evans" <dd*****@hotmail.com> wrote in message
news:40***********************@mercury.nildram.net ...

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking system for these camps.


news://comp.database.ms-access
Jul 19 '05 #6

"Dan Evans" <dd*****@hotmail.com> wrote in message
news:40***********************@mercury.nildram.net ...

Can anyone help me on a little problem I am having with some SQL - in
particular on a subquery.

I am setting up a database in Access for a voluntary group which runs
voluntary youth weekend camps. The bit I am on at the moment is the booking system for these camps.


news://comp.database.ms-access
Jul 19 '05 #7

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

Similar topics

7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
8
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...
7
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of...
1
by: Docster2005 | last post by:
Hi folks, A DTS package we have run for years now no longer works. The specific part that is not working is a subquery in the SOURCE object of a transformation. The source is based on a...
8
by: Mike Jolley | last post by:
Hello First off, I'm a student so I'm pretty new to C++, and therefore I have probably made a stupid mistake somewhere. Anyway Ive been trying to fix this 5 hours straight now, so i need a...
6
by: iazahoor | last post by:
I use Access 2000 and I'm trying to figure out what VBA code to use to prevent double bookings. Any help on this matter will be greatly appreciated. Regards Immy
3
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
4
by: phill86 | last post by:
Hi, I am trying to represent on a form time slots I have re-created the look of an outlook calendar on the form I have a table with the calendar bookings start and end time and there could be any...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
1
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
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...
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.