Home > Database > Mysql Tutorial > How to Properly Alias Tables in Oracle SQL Queries?

How to Properly Alias Tables in Oracle SQL Queries?

Patricia Arquette
Release: 2025-01-15 08:27:49
Original
422 people have browsed it

How to Properly Alias Tables in Oracle SQL Queries?

Correct use of table aliases in Oracle SQL queries

When aliasing a table using the AS keyword in Oracle, you may encounter the error "ORA-00933: SQL command not properly ended". This error stems from Oracle not supporting table aliasing using the AS keyword.

In Oracle, the syntax for table aliases is a comma-separated list of table names, followed by a colon (:), and then the desired alias. For example:

<code class="language-sql">SELECT G.Guest_ID, G.First_Name, G.Last_Name
FROM Guest, Stay S
WHERE G.Guest_ID = S.Guest_ID AND G.City = 'Miami' AND S.Room = '222';</code>
Copy after login

Or the more recommended modern SQL standard JOIN syntax:

<code class="language-sql">SELECT G.Guest_ID, G.First_Name, G.Last_Name
FROM Guest G
JOIN Stay S ON G.Guest_ID = S.Guest_ID
WHERE G.City = 'Miami' AND S.Room = '222';</code>
Copy after login

To resolve the error in the original query, simply remove the AS keyword. The second example above shows a cleaner, more maintainable JOIN syntax that avoids the ambiguity of implicit joins and makes the join conditions explicit. Modern SQL development strongly recommends using JOIN syntax. While Oracle allows the old-style comma-separated join syntax, it is error-prone and difficult to read.

This modified query will execute successfully without table aliasing using the AS keyword.

The above is the detailed content of How to Properly Alias Tables in Oracle SQL Queries?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template