473,385 Members | 1,655 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.

posted for the 2 time and still no reply, is it hard for you?

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?
Nov 25 '06 #1
7 1364
nico5038
3,080 Expert 2GB
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)
Nov 25 '06 #2
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).
Nov 25 '06 #3
ADezii
8,834 Expert 8TB
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));
Nov 25 '06 #4
willakawill
1,646 1GB
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;
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT student_name 
  2. FROM registration 
  3. WHERE course_name='english' AND 'math'
  4.  
Of course we can't write a where clause like this so we need to change this slightly to get exactly what you want;
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT student_name 
  2. FROM registration 
  3. WHERE course_name='english' 
  4. AND course_name ='math'
  5.  
  6.  
Nov 25 '06 #5
nico5038
3,080 Expert 2GB
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)
Nov 25 '06 #6
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.
Nov 25 '06 #7
willakawill
1,646 1GB
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
Nov 26 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

17
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...
7
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...
77
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...
9
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...
17
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...
2
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...
6
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...
2
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...
0
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,...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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,...
0
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,...
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...

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.