Hi everyone,
I have created a table with the following 3 columns
ID UserID SkillID
1 2 1
1 2 3
1 2 2
1 3 2
Is there a way to return all UserIDs that match SkillID=1 and SkillID=2 and
SkillID=3? (not OR)
Thank you
Maziar A. 7 1478
If 1, 2 and 3 are the _only_ allowed values for SkillID you can...
SELECT ID, UserID, count(SkillID) FROM <TableName> GROUP BY ID, UserID
Then those rows with a 3 in the third column are what you're looking
for.
May be wrong, my sql is a little rusty lately :D
On 18 May 2005 09:09:43 -0700, "Samuel (lets dot monroe at gmail dot
com)" <le*********@gmail.com> wrote: If 1, 2 and 3 are the _only_ allowed values for SkillID you can...
SELECT ID, UserID, count(SkillID) FROM <TableName> GROUP BY ID, UserID
Then those rows with a 3 in the third column are what you're looking for.
Use HAVING to filter on the result of count():
SELECT ID, UserID, count(SkillID) FROM <TableName> GROUP BY ID, UserID
HAVING count(SkillID)=3
This also assumes a unique constraint on UserID and SkillID preventing
the same SkillID appearing multiple times for one UserID.
--
David ( @priz.co.uk )
This would be a mysql question... try the mysql group..
I'm not sure, but I think this would be a self join
SELECT *
FROM table, table as table_copy
WHERE table.UserID = table_copy.UserID
AND table.SkillID = 1
AND table.SkillID = 2
AND table.SkillID = 3
or maybe something like:
SELECT UserID, SkillID,
GROUP_CONCAT(SkillID ORDER BY test_score DESC SEPARATOR ' ') as skills
FROM table
WHERE skills = '1 2 3'
GROUP BY UserID
SELECT UserID FROM tablename WHERE UserID IN (SELECT UserID FROM tablename
WHERE SkillID=1) AND UserID IN (SELECT UserID FROM tablename WHERE
SkillID=2) AND UserID IN (SELECT UserID FROM tablename WHERE SkillID=3)
However, it may be more efficient for you to redesign your database.
ECRIA http://www.ecria.com
David Mackenzie ha escrito: This also assumes a unique constraint on UserID and SkillID
preventing the same SkillID appearing multiple times for one UserID.
Yep, I assumed that from the fact that (as far as we know anyway) the
table has only three columns, so if ID and UserID can repeat SkillID
can't :)
I noticed that Message-ID: <d6**********@murdoch.acc.Virginia.EDU> from
ECRIA Public Mail Buffer contained the following: SELECT UserID FROM tablename WHERE UserID IN (SELECT UserID FROM tablename WHERE SkillID=1) AND UserID IN (SELECT UserID FROM tablename WHERE SkillID=2) AND UserID IN (SELECT UserID FROM tablename WHERE SkillID=3)
Can you do that in MySQL now?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Geoff Berrow (bl******@ckdog.co.uk) decided we needed to hear... SELECT UserID FROM tablename WHERE UserID IN (SELECT UserID FROM tablename WHERE SkillID=1) AND UserID IN (SELECT UserID FROM tablename WHERE SkillID=2) AND UserID IN (SELECT UserID FROM tablename WHERE SkillID=3)
Can you do that in MySQL now?
IIRC sub-selects came in at v4.1
--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Westcoast Sheri |
last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database
(2 columns: "fruit" and "quantity")....so can we make these following
mySQL queries work somehow?
(visitor buys 5...
|
by: MJL |
last post by:
This is a mysql/php question (but a little more on the mysql side.)
The two are so closely related these days, I thought it would be ok to
ask here.
I installed on my Suse Linux system mysql 4.0...
|
by: Tony Clarke |
last post by:
Hi,
Just a quick question about performance with MySQL & PHP. If I had a table
in a MySQL database with about 100,000 records in it and I need to find the
last record is there a quick way to do...
|
by: pieter_hordijk |
last post by:
Hi all,
maybe this isn't a php question, but a MySQL question.
If so I'm sorry for asking you guys to help me :)
I know this question is asked often in NGs, but I couldn't find the
answer...
|
by: kimshapiro100 |
last post by:
Question on PhP, MySQL
I am thinking of a consumer internet business for which I will have to
have a database driven site built.
I am thinking of using
PhP, MySQL as the main technologies...
|
by: Mairhtin O'Feannag |
last post by:
Hello,
I have a client (customer) who asked the question : "Why would I buy and
use UDB, when MySql is free?"
I had to say I was stunned. I have no experience with MySql, so I was
left sort...
|
by: Jim Carlock |
last post by:
I have a couple questions about MySQL involving which
version of MySQL to use.
I'm looking for minimal memory use on a Windows XP machine.
Which version would be best for this? And can anyone...
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to...
|
by: news.telia.net |
last post by:
Hi!
I have a question. I have installed php and mysql on an apache-server on
windows and I can't connect to the server.
I tried to create a database (since I am trying to learn howto). My...
|
by: gerrymcc |
last post by:
Hello, I'm a php/mysql beginner...
Is there any way of making the mysql command line client full-screen?
Sometimes it's easier to use the client than go thru php, but
since it's only about 80...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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: 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...
|
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...
|
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...
| |