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

how to create a query.

I'm so sorry for posting this message again 'cause there's a lot of
error in my previous posting...

I'm having problem w/ my query on how to filter a record based on the
criteria i give.

here's the tables

students table
id
program

course table
courseid
id
program
course

for example if i have this data on my table

id students.program course.program course
1 BEED BSED FIL 2
2 BEED FIL 2
3 BEED ENG 2
4 BSED FIL 2

based on the above example. if i want to query a course field = FIL 2
and if program = BSED the result should be:

id students.program course.program course
1 BEED BSED FIL 2
4 BSED FIL 2

but if i query course field = FIL 2 and program = BEED the result
should be:

id students.program course.program course
2 BEED FIL 2

the point here is that if course.program field is not empty the
criteria is based in course.program but if it is empty the criteria is
based on students.program.

hope i explained it well.
Nov 13 '05 #1
3 1368
Try this. In your query make a column that has the following as is heading:

Prog: IIf(IsNull([Courses].[Program]),[Students].[Program],[Courses].[Program])

This should give you the results you want when you put in the criteria.
jaYPee <hi******@yahoo.com> wrote in message news:<ij********************************@4ax.com>. ..
I'm so sorry for posting this message again 'cause there's a lot of
error in my previous posting...

I'm having problem w/ my query on how to filter a record based on the
criteria i give.

here's the tables

students table
id
program

course table
courseid
id
program
course

for example if i have this data on my table

id students.program course.program course
1 BEED BSED FIL 2
2 BEED FIL 2
3 BEED ENG 2
4 BSED FIL 2

based on the above example. if i want to query a course field = FIL 2
and if program = BSED the result should be:

id students.program course.program course
1 BEED BSED FIL 2
4 BSED FIL 2

but if i query course field = FIL 2 and program = BEED the result
should be:

id students.program course.program course
2 BEED FIL 2

the point here is that if course.program field is not empty the
criteria is based in course.program but if it is empty the criteria is
based on students.program.

hope i explained it well.

Nov 13 '05 #2
jaYPee <hi******@yahoo.com> wrote in message news:<ij********************************@4ax.com>. ..
students table
id
program

course table
courseid
id
program
course

for example if i have this data on my table

id students.program course.program course
1 BEED BSED FIL 2
2 BEED FIL 2
3 BEED ENG 2
4 BSED FIL 2

based on the above example. if i want to query a course field = FIL 2
and if program = BSED the result should be:

id students.program course.program course
1 BEED BSED FIL 2
4 BSED FIL 2

but if i query course field = FIL 2 and program = BEED the result
should be:

id students.program course.program course
2 BEED FIL 2


A simple technique that avoids IIF is:

SELECT students.id, students.program, course.program, course FROM
students INNER JOIN course ON students.id = course.id WHERE
((students.program='BEED') AND (course.program Is Null)) OR
((course.program='BEED'));

Including a criteria for course would look something like:

SELECT students.id, students.program, course.program, course FROM
students INNER JOIN course ON students.id = course.id WHERE
((students.program='BEED') AND (course.program Is Null) AND
(course.course='ENG 2')) OR ((course.program='BEED') AND
(course.course='ENG 2'));

Test Results using your data:

SELECT students.id, students.program, course.program, course.course
FROM students INNER JOIN course ON students.id = course.id
WHERE (((students.program)='BSED') AND ((course.program) Is Null) AND
((course.course)="FIL 2")) OR (((course.program)='BSED') AND
((course.course)="FIL 2"));

produced:

1 BEED BSED FIL 2
4 BSED FIL 2

SELECT students.id, students.program, course.program, course.course
FROM students INNER JOIN course ON students.id = course.id
WHERE (((students.program)='BEED') AND ((course.program) Is Null) AND
((course.course)="FIL 2")) OR (((course.program)='BEED') AND
((course.course)="FIL 2"));

produced:

2 BEED FIL 2

The technique is still the same if I have misread how you are doing
the join.

James A. Fortune
Nov 13 '05 #3
Thank you very much. it works.

I need to put the is null in the criteria...
:)

jaYPee

On 16 Nov 2004 13:06:59 -0800, ja******@oakland.edu (James Fortune)
wrote:
jaYPee <hi******@yahoo.com> wrote in message news:<ij********************************@4ax.com>. ..
students table
id
program

course table
courseid
id
program
course

for example if i have this data on my table

id students.program course.program course
1 BEED BSED FIL 2
2 BEED FIL 2
3 BEED ENG 2
4 BSED FIL 2

based on the above example. if i want to query a course field = FIL 2
and if program = BSED the result should be:

id students.program course.program course
1 BEED BSED FIL 2
4 BSED FIL 2

but if i query course field = FIL 2 and program = BEED the result
should be:

id students.program course.program course
2 BEED FIL 2


A simple technique that avoids IIF is:

SELECT students.id, students.program, course.program, course FROM
students INNER JOIN course ON students.id = course.id WHERE
((students.program='BEED') AND (course.program Is Null)) OR
((course.program='BEED'));

Including a criteria for course would look something like:

SELECT students.id, students.program, course.program, course FROM
students INNER JOIN course ON students.id = course.id WHERE
((students.program='BEED') AND (course.program Is Null) AND
(course.course='ENG 2')) OR ((course.program='BEED') AND
(course.course='ENG 2'));

Test Results using your data:

SELECT students.id, students.program, course.program, course.course
FROM students INNER JOIN course ON students.id = course.id
WHERE (((students.program)='BSED') AND ((course.program) Is Null) AND
((course.course)="FIL 2")) OR (((course.program)='BSED') AND
((course.course)="FIL 2"));

produced:

1 BEED BSED FIL 2
4 BSED FIL 2

SELECT students.id, students.program, course.program, course.course
FROM students INNER JOIN course ON students.id = course.id
WHERE (((students.program)='BEED') AND ((course.program) Is Null) AND
((course.course)="FIL 2")) OR (((course.program)='BEED') AND
((course.course)="FIL 2"));

produced:

2 BEED FIL 2

The technique is still the same if I have misread how you are doing
the join.

James A. Fortune


Nov 13 '05 #4

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

Similar topics

5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
6
by: sheree | last post by:
I would like to create a query where one of the columns of the queries comes from a combo list box on a form. For example, if my table has the following fields: id name interest1 interest2...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
18
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
2
by: angie | last post by:
I need to figure out how to create a user interface to search a query, but here's the bad part...I need to account for criteria on at least 7 of the fields. Here's what I'm thinking I need to do:...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
15
by: harvey | last post by:
How do I make PHP create a database for mysql please? I can see how to make tables and I have read all the documents I can find but I don't understand how to make the database itself. All...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.