Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Newbie: Simple select with 'IN ALL'
Comments
-
select person,count(id_state) from project group by person having count(id_state)=3;Problem is that this will select any people with exactly 3 rows, so someone with 1, 2, 6 would also be in.
-
ya sorry for my mistake.
This is the latest query for doing this
select person,count(case when id_state=2 then id_state when id_state=3 then id_state when id_state=4 then id_state end) as count1 from project group by person having count1=3;
Try this one. -
This is probably the shortest query though:
select person from project where id_state in (2, 3, 4) group by person having count(*) = 3
-
you are right. What i was thinking that in case of IN it will consider all others also. Now it's time to recall all the stuff for me.
-
This is probably the shortest query though:but would give wrong result in case duplicate records exist in the table!
-
but would give wrong result in case duplicate recordsThis is probably the shortest query though:but would give wrong result in case duplicate records
exist in the table!exist in the table!What do you mean by duplicate records in table?
any example. -
Hi,
lets suppose we have data asSQL> select * from PROJECT6030 order by 2;
In this case our quiery should select Mark as Mark has all three Id states.
ID_PROJECT PERSON ID_STATE LAST_UPDA
---------- ---------- ---------- ---------
6 Carl 4 22-JAN-05
5 Carl 3 08-DEC-04
1 Joe 3 08-AUG-07
2 Mark 2 05-JUL-07
4 Mark 4 14-MAR-07
3 Mark 3 27-JUN-07
8 Mark 3 10-MAY-07
8 Paul 1 30-JUL-07
9 Paul 2 02-JUN-06
7 Sam 3 11-JUL-06
7 Sam 2 15-JUN-06
11 rows selected.
Now consider the quiery.SQL> ed
when you group by count(*) we see that no person is having 3 rows of data.
Wrote file afiedt.buf
1 select person from project6030
2 where id_state in (2, 3, 4)
3 group by person
4* having count(*) = 3
5 /
no rows selected
now lets see another quiery which Volder had posted in the begining.SQL> ed
Thank you all for your responses!!
Wrote file afiedt.buf
1 select person from project6030
2 where id_state in (2, 3, 4)
3 group by person
4* having count(distinct id_state) = 3
SQL> /
PERSON
----------
Mark -
Thnks User575882 to clear my doubt.
You got the solutioon of your problem? -
More discussion and suggestions for relational division:
groups.google.com/group/comp.databases.oracle.misc/browse_thread/thread/576ea61b1a93469b/74a1a03238b6d97b?lnk=gst
@NightCabbage:
> Oracle is like that.
Perhaps, but relational division has historically always been tricky in the SQL language. I don't know whether other vendors make this type of query any easier. -
...so using COLLECT and SUBMULTISET as in Maxim Demenko's post on c.d.o.m, we get this:
WITH project AS
"INTEGER_TT" is my nested table collection type, defined as
( select 'Carl' person, 3 id_state from dual union all
select 'Carl', 4 from dual union all
select 'Joe', 3 from dual union all
select 'Mark', 2 from dual union all
select 'Mark', 3 from dual union all
select 'Mark', 4 from dual union all
select 'Paul', 1 from dual union all
select 'Paul', 2 from dual union all
select 'Sam', 2 from dual union all
select 'Sam', 3 from dual )
--
SELECT person
FROM project
GROUP BY person
HAVING integer_tt(2,3,4) SUBMULTISET OF CAST(COLLECT(id_state) AS integer_tt) ;CREATE TYPE integer_tt AS TABLE OF INTEGER
This discussion has been closed.