Home » SQL & PL/SQL » SQL & PL/SQL » Help needed to solve this sql
Help needed to solve this sql [message #262244] Sat, 25 August 2007 10:30 Go to next message
arv123
Messages: 1
Registered: August 2007
Location: Chennai
Junior Member

I tried this below SQL and ended up with an error saying sql command not properly ended. Can't I do this? I'm new to Oracle the same this works in MySql in which I have some knowledge.

SELECT COMPANY_ID,CMP_ALIAS_ID FROM T1 (
SELECT COMPANY_ID,0 AS CMP_ALIAS_ID FROM COMPANY WHERE COMPANY_NAME LIKE 'i%'
UNION
SELECT COMPANY_ID,CMP_ALIAS_ID FROM Cmp_Aliases WHERE Alias_Name LIKE 'i%' ORDER BY CMP_ALIAS_ID) AS T1 ;

Thanks in Advance
ARV


Re: Help needed to solve this sql [message #262247 is a reply to message #262244] Sat, 25 August 2007 11:27 Go to previous message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
Welcome to the forum.

The SQL you posted is not syntactically valid in Oracle.
The use of table alias is slightly different and should be
SELECT COMPANY_ID,CMP_ALIAS_ID
FROM (
SELECT COMPANY_ID,0 AS CMP_ALIAS_ID 
  FROM COMPANY
  WHERE COMPANY_NAME LIKE 'i%'
UNION
SELECT COMPANY_ID,CMP_ALIAS_ID
  FROM Cmp_Aliases
  WHERE Alias_Name LIKE 'i%'
ORDER BY CMP_ALIAS_ID
) T1 ;
By the way there is no (functional) need for the outer query.

For correct syntax please consult Oracle Database SQL Reference.
Its link (The Online Documentation) can be found in How to get a quick answer to your question: TIPS AND TRICKS sticky post (the first one in the forum).
Also when posting code, please use format tags as described in the above post.
Previous Topic: How to recompile package second time
Next Topic: Dynamically controlling the flow of the script
Goto Forum:
  


Current Time: Sat Dec 03 05:40:11 CST 2016

Total time taken to generate the page: 0.05034 seconds