Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Selecting ID with same statuses column

mikrimouseDec 12 2018 — edited Dec 18 2018

I m have this select  select bus_session_session_id,status from items; and need to distinct bus_session_session_id  where status is W.  So if   session_id has two statuses W and L , I want  just to select session_id where all status for that session_id is  W.

enter image description here

So for example in this session_id 537438 i have two  status W, so i need query which will check if all statuses are W and select those session ids . If one of them is L then dont select that session id.

I was trying something with this , and with some modifying but cant get what i need..

SELECT *

FROM items

WHERE bus_sessioN_sessioN_id IN (

    SELECT bus_sessioN_sessioN_id

    FROM items

    GROUP BY bus_sessioN_sessioN_id

    HAVING COUNT(distinct status) > 1);

How will i accomplish that ? Thanks

This post has been answered by mathguy on Dec 12 2018
Jump to Answer
Comments
Post Details
Added on Dec 12 2018
6 comments
777 views