|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
UNION/select query, returns an error -solved
Never mind! solved
This is how my table looks like: Code:
Name Null? Type ----------------------------------------- -------- ------------- OPPONENT VARCHAR2(25) MATCH_DATE DATE MATCH_TIME VARCHAR2(10) LOCATION VARCHAR2(20) LEAGUE VARCHAR2(30) this is what my query is: Code:
select *from ( select 'Charlton vs '||Opponent as Team, match_date, Match_time, Location, League from charlton_games@charlton1 UNION select 'Liverpool vs '||Opponent as Team, match_date, Match_time, Location, League from liverpool_games@liverpool1 UNION select 'Portsmouth vs '||Opponent as Team, match_date, Match_time, Location, League from portsmouth_games@portsmouth1 UNION select 'Man U vs '||Opponent as Team, match_date, Match_time, Location, League from man_u_games@man_u1) where opponent = 'Everton' and Match_Date>Sysdate Order by Match_Date; but it gives me an error on opponent in the where clause! |
|
#2
|
|||
|
|||
|
That's because the derived table (the "inner" select) does not have a LoCATION column. The inner select returns a result set that has two columns: one named team the other named match_date.
If you want to limit to location = 'HOME' you need to include that in every single select for the UNION or it to the inner select. Code:
SELECT team, match_date
FROM (
SELECT 'Charlton vs ' ||opponent AS team,
match_date,
location
FROM charlton_games@charlton1
UNION
SELECT 'Liverpool vs ' ||opponent AS team,
match_date,
location
FROM liverpool_games@liverpool1
UNION
SELECT 'Portsmouth vs ' ||opponent AS team,
match_date,
location
FROM portsmouth_games@portsmouth1
UNION
SELECT 'Crystal Palace vs ' ||opponent AS team,
match_date,
location
FROM palace_games@palace1
UNION
SELECT 'MAN U vs ' ||opponent AS team,
match_date,
location
FROM man_u_games@man_u1
)
WHERE location = 'Home';
|
|
#3
|
|||
|
|||
|
Never mind!
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > UNION/select query, returns an error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|