SQL query - Selecting distinct values from a table
oracle, sql
Solution
try the following :-
select distinct fk_col from table1
minus
(select distinct fk_col from table1 where col_entry='ab3'
intersect
select distinct fk_col from table1 where col_entry='ab4')
This will show all those FKs which do not have 'ab3' and 'ab4'. i.e. 100 and 200 in your case
Problem
I have a table in which i have multiple entries against a FK. I want to find out the value of FK which do not have certain entries e.g my table has following entries. ``` PK----------------FK-----------------Column entries 1----------------100-----------------ab1 2----------------100-----------------ab2 3----------------100-----------------ab4 4----------------200-----------------ab1 5----------------200-----------------ab2 6----------------200-----------------ab3 7----------------300-----------------ab1 8----------------300-----------------ab2 9----------------300-----------------ab3 10---------------300-----------------ab4 ``` Now, from this table i want to filter all those FK which do not have ab3 or ab4 in them. Certainly, i expect distinct values i.e. in this case result would be FK= 100 and 200. The query which i am using is ``` select distinct(FK) from table1 where column_entries != 'ab3' or column_entries != 'ab4'; ``` Certainly, this query is not fetching the desired result.