I am developing web application using JSP and Servlet (IDE: Eclipse, Container: Tomcat7.0, DB: Oracle 10)
I want to get data from two table in a single query
Query:
query = "select * from PROTOCOL as a, ACTIONS as b where a.PROTOCOL_ID = b.PROTOCOL_ID";
But after running the application I am getting the following exception:
java.sql.SQLException: ORA-00933: SQL command not properly ended
is there anything wrong in query?
3 Answers 3
The problem you have is keyword AS. This is used for columns in SELECT section. It is not valid for FROM where you specify the tables.
You have
select * from PROTOCOL as a, ACTIONS as b
should be
select * from PROTOCOL a, ACTIONS b...
From Oracle Docs
t_alias
Specify a correlation name, which is alias for the table, view, materialized view, or subquery for evaluating the query. This alias is required if the select list references any object type attributes or object type methods. Correlation names are most often used in a correlated query. Other references to the table, view, or materialized view throughout the query must refer to this alias.
Example:
SELECT select_list
FROM table1 t_alias1
WHERE expr operator
(SELECT column_list
FROM table2 t_alias2
WHERE t_alias1.column
operator t_alias2.column);
7 Comments
as grammer.As there because it is not allowed.AS, I admit I never used it...wrong alias syntax. try the following:
query = "select * from PROTOCOL a,ACTIONS b where a.PROTOCOL_ID = b.PROTOCOL_ID";
1 Comment
A comment here for anyone may need it.. PostgreSQL seems to accept AS next to FROM/JOIN