views:

83

answers:

1

Suppose I have two tables Table1 and Table2 with the following data.

Column1 Column2 Column3
AAA      KKK       9
BBB      LLL       7
CCC      MMM       9
DDD      MMM       5
EEE      MMM       7
FFF      NNN       9
GGG      OOO       1


Column4 Column1
TTT      DDD
TTT      BBB
UUU      EEE
VVV      BBB
WWW      AAA
WWW      BBB
XXX      DDD
YYY      EEE
YYY      DDD
YYY      CCC
YYY      FFF

The query is of selecting "select value(s) from column4 which matches the tuple result of column1 when column2 has the value 'MMM'('CCC','DDD','EEE') this result should match with all results from column4" the result is 'YYY'

The error message is

    SELECT DISTINCT t2.Column4
     FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.Column1 = t2.Column1
    WHERE Column2 = 'MMM'
 GROUP BY t1.Column2
   HAVING COUNT(t1.Column1) = COUNT(t2.Column1)
         *
    ERROR at line 1:
 ORA-00904: "T1"."Column1": invalid identifier
+2  A: 
   SELECT t2.Column4
     FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.Column1 = t2.Column1
    WHERE Column2 = 'MMM'
 GROUP BY t2.Column4
   HAVING COUNT(t1.Column1) = COUNT(t2.Column4)

What about this query?

zerkms
I think t1.column1 is not a GROUP BY expression
Sana
I've changed it several times ;-) It's a bit difficult to keep in mind such query execution ;-)
zerkms
It says that [HAVING COUNT(t1.Column1) = COUNT(t2.Column4)] is not a GROUP BY expression
Sana
Copy-paste the complete error as-is.
zerkms
See the question. I just editted it with the error message
Sana
1. Ora!?!?!? 2. I don't see any `MOVIE` column in the query. put actual query please
zerkms
I am using Oracle here! Updated
Sana
This error means that there is no `Column1` in table `t1`
zerkms
Column1 exists.
Sana
Oracle said it is not.
zerkms
This query works perfectly in MySQL but errors out in Oracle! Strange!
Sana