IT IS THE SECOND TIME I POST THIS PROBLEM, AND STILL NO REPLY, IS IT HARD TO FIND A SOLUTION?
AGAIN:
Table name: registration
Fields: registration_number....................student_nam e.............course_name
1................................................. .......mike..............................english
2 .................................................. .....lara................................french
3 .................................................. .....peter..............................math
4 .................................................. .....mike..............................math
Query= SELECT student_name FROM registration WHERE course_name="english" AND "math";
the query should give back: "mike", since mike is the only student who is taking "english" and "math" at the same time.
Simply, the query is not working, I know it is not the right way to get what i want, but WHAT IS THE RIGHT WAY?
7 1364
Hmm, strange to have a mike registred twice, but to query that use:
select count(*), student_name from registration where course_name in ("english","math")
group by student_name
having count(*) = 2;
This will count the number of matching courses and only select those having the match with all courses.
Nic;o)
NeoPa 32,556
Expert Mod 16PB
Desperadou,
Nico's solution perfectly answers your problem.
However, please understand that this is a web site where members offer their time and expertise for free.
It is not your RIGHT to expect answers at all. If you get no response (which is very rare in my experience) you are still receiving value for money (It is, after all, free).
Having said that, if you notice it, you are very welcome to bring it to our attention (politely of course).
IT IS THE SECOND TIME I POST THIS PROBLEM, AND STILL NO REPLY, IS IT HARD TO FIND A SOLUTION?
AGAIN:
Table name: registration
Fields: registration_number....................student_nam e.............course_name
1................................................. .......mike..............................english
2 .................................................. .....lara................................french
3 .................................................. .....peter..............................math
4 .................................................. .....mike..............................math
Query= SELECT student_name FROM registration WHERE course_name="english" AND "math";
the query should give back: "mike", since mike is the only student who is taking "english" and "math" at the same time.
Simply, the query is not working, I know it is not the right way to get what i want, but WHAT IS THE RIGHT WAY?
SELECT registration.student_name, Count(registration.student_name) AS Course_Count
FROM registration
WHERE (((registration.course_name)="english" Or (registration.course_name)="math"))
GROUP BY registration.student_name
HAVING (((Count(registration.student_name))>1));
IT IS THE SECOND TIME I POST THIS PROBLEM, AND STILL NO REPLY, IS IT HARD TO FIND A SOLUTION?
AGAIN:
Table name: registration
Fields: registration_number....................student_nam e.............course_name
1................................................. .......mike..............................english
2 .................................................. .....lara................................french
3 .................................................. .....peter..............................math
4 .................................................. .....mike..............................math
Query= SELECT student_name FROM registration WHERE course_name="english" AND "math";
the query should give back: "mike", since mike is the only student who is taking "english" and "math" at the same time.
Simply, the query is not working, I know it is not the right way to get what i want, but WHAT IS THE RIGHT WAY?
You almost have it in your query.
First, I imagine that you only want to see Mike once in the query output so we should modify your sql statement this way; -
SELECT DISTINCT student_name
-
FROM registration
-
WHERE course_name='english' AND 'math'
-
Of course we can't write a where clause like this so we need to change this slightly to get exactly what you want; -
SELECT DISTINCT student_name
-
FROM registration
-
WHERE course_name='english'
-
AND course_name ='math'
-
-
Sorry willakawill, but:
SELECT student_name
FROM registration
WHERE course_name='english'
AND course_name ='math'
will give no output at all as the field [course_name] will never hold both valuesat the same time....
Only an OR relation could work, but will result in two records.
Nic;o)
NeoPa 32,556
Expert Mod 16PB
ALL answers are, of course, welcomed (and encouraged :) ).
In this thread though, I draw your attention to Nico's answer as it handles every point perfectly.
I considered :embarrassed: a correction myself earlier along the lines suggested by ADezii, but then I looked again and realised that =2 is actually the more correct.
>1 will work, but there can only ever be two (assuming that there will never be a duplicate of all the three fields), because of the WHERE clause.
Sorry willakawill, but:
SELECT student_name
FROM registration
WHERE course_name='english'
AND course_name ='math'
will give no output at all as the field [course_name] will never hold both valuesat the same time....
Only an OR relation could work, but will result in two records.
Nic;o)
Yup. My bad. Thank you.
Both of the other suggestions work
Sign in to post your reply or Sign up for a free account.
Similar topics
by: los |
last post by:
Hi,
I'm trying to create a program similar to that of Google's desktop that
will crawl through the hard drive and index files. I have written the
program and as of now I just put the thread to...
|
by: TT |
last post by:
As title
|
by: Jan Roland Eriksson |
last post by:
I'm posting a revised version of the meta FAQ for this NG.
Beware that there are a few links in there that does not have a resource
available for them yet but, over and all, this following document...
|
by: Charles Law |
last post by:
Hi guys
I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in a
specific time frame. The time when the...
|
by: scott |
last post by:
I have a field with datetime values like below LISTING 1. Can someone help
me write code strip the time part so only values like "7/15/2005" will be
left.
Note - We must be able to strip dates...
|
by: Eric Lindsay |
last post by:
Is learning to write CSS a better use of time than finding and using a
package that produces complete web pages?
I've moved to a new platform (Macintosh), taking with me about 400
personal web...
|
by: TerryW |
last post by:
I am using a system.windows.forms.datagrid and i set it's data
source to a system.data.datatable which has a column that's
dataType is system.dateTime. When I try to enter minutes and
seconds...
|
by: arnuld |
last post by:
I don't understand, every week I post "Welcome Message" as a new post
and it gets posted as reply to my older "Welcome Message",
automatically. What exactly is happening ?
I have tried both PAN...
|
by: Blubaugh, David A. |
last post by:
To All,
I have done some additional research into the possibility of utilizing
Python for hard real time development. I have seen on various websites
where this has been discussed before on...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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,...
|
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...
| | |