table-alias

SQL - table alias scope

£可爱£侵袭症+ 提交于 2019-12-03 15:04:27
问题 I've just learned ( yesterday ) to use "exists" instead of "in". BAD select * from table where nameid in ( select nameid from othertable where otherdesc = 'SomeDesc' ) GOOD select * from table t where exists ( select nameid from othertable o where t.nameid = o.nameid and otherdesc = 'SomeDesc' ) And I have some questions about this: 1) The explanation as I understood was: "The reason why this is better is because only the matching values will be returned instead of building a massive list of

SQL - table alias scope

只谈情不闲聊 提交于 2019-12-03 03:55:32
I've just learned ( yesterday ) to use "exists" instead of "in". BAD select * from table where nameid in ( select nameid from othertable where otherdesc = 'SomeDesc' ) GOOD select * from table t where exists ( select nameid from othertable o where t.nameid = o.nameid and otherdesc = 'SomeDesc' ) And I have some questions about this: 1) The explanation as I understood was: "The reason why this is better is because only the matching values will be returned instead of building a massive list of possible results" . Does that mean that while the first subquery might return 900 results the second

Why is selecting specified columns, and all, wrong in Oracle SQL?

一曲冷凌霜 提交于 2019-11-29 01:12:29
Say I have a select statement that goes.. select * from animals That gives a a query result of all the columns in the table. Now, if the 42nd column of the table animals is is_parent , and I want to return that in my results, just after gender , so I can see it more easily. But I also want all the other columns. select is_parent, * from animals This returns ORA-00936: missing expression . The same statement will work fine in Sybase, and I know that you need to add a table alias to the animals table to get it to work ( select is_parent, a.* from animals ani ), but why must Oracle need a table

oracle: can you assign an alias to the from clause?

北战南征 提交于 2019-11-28 03:21:21
问题 can you assign an alias to the from clause? like: select a - b "Markup" from retail a, cost b; EDIT: sorry i typed that out a bit too quick and tried to simplify the question to the point where it didnt make any sense What im actually trying to do is use aliases to compare the months between two publishing dates in the same table. Here's what i found works: select distinct to_char(months_between((select distinct pubdate from books3 where pubid = 2), (select distinct pubdate from books3 where

SQL Command not properly ended?

匆匆过客 提交于 2019-11-28 01:52:13
I am using a SQL statement with a Temporary relation, and am getting the error ORA-009933: SQL command not properly ended I don't see anything wrong with the statement, so any assistance is greatly appreciated. The statement is: SELECT Temp.name, Temp.AvgSalary FROM (SELECT A.aid, A.aname AS name, AVG(E.salary) AS AvgSalary FROM Aircraft A, Certified C, Employees E) AS Temp; Thanks oracle does not support as for table aliases, only for column aliases and they are optional for that use => delete all as keywords ;) You shouldn't put the AS temp. When putting alias to a table (or subquery) you

Why is selecting specified columns, and all, wrong in Oracle SQL?

穿精又带淫゛_ 提交于 2019-11-27 15:42:15
问题 Say I have a select statement that goes.. select * from animals That gives a a query result of all the columns in the table. Now, if the 42nd column of the table animals is is_parent , and I want to return that in my results, just after gender , so I can see it more easily. But I also want all the other columns. select is_parent, * from animals This returns ORA-00936: missing expression . The same statement will work fine in Sybase, and I know that you need to add a table alias to the animals

SQL Command not properly ended?

萝らか妹 提交于 2019-11-26 22:01:59
问题 I am using a SQL statement with a Temporary relation, and am getting the error ORA-009933: SQL command not properly ended I don't see anything wrong with the statement, so any assistance is greatly appreciated. The statement is: SELECT Temp.name, Temp.AvgSalary FROM (SELECT A.aid, A.aname AS name, AVG(E.salary) AS AvgSalary FROM Aircraft A, Certified C, Employees E) AS Temp; Thanks 回答1: oracle does not support as for table aliases, only for column aliases and they are optional for that use =>

Using Alias in query resulting in “command not properly ended”

守給你的承諾、 提交于 2019-11-26 18:39:44
问题 I tried this: SELECT * FROM (SELECT * , ROW_NUMBER() OVER (ORDER BY vernum DESC, defvern DESC) AS RowNumber FROM MyTable INNER JOIN AnotherTable ON MyTable.id = AnotherTable.dataid WHERE MyTable.defid = 123456 AND MyTable.attrid = 10) AS a WHERE a.RowNumber = 1; I get this error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" *Cause: *Action: Error at Line: 8 Column: 37 When I remove AS a and the WHERE a.RowNumber = 1; the query works fine. Is there

When to use SQL Table Alias

那年仲夏 提交于 2019-11-26 12:31:02
I'm curious to know how people are using table aliases. The other developers where I work always use table aliases, and always use the alias of a, b, c, etc. Here's an example: SELECT a.TripNum, b.SegmentNum, b.StopNum, b.ArrivalTime FROM Trip a, Segment b WHERE a.TripNum = b.TripNum I disagree with them, and think table aliases should be use more sparingly. I think they should be used when including the same table twice in a query, or when the table name is very long and using a shorter name in the query will make the query easier to read. I also think the alias should be a descriptive name

How to use the 'as' keyword to alias a table in Oracle?

大兔子大兔子 提交于 2019-11-26 10:47:18
I'm trying to execute this query in Oracle SQL Developer: SELECT G.Guest_ID, G.First_Name, G.Last_Name FROM Guest AS G JOIN Stay AS S ON G.Guest_ID = S.Guest_ID WHERE G.City = 'Miami' AND S.Room = '222'; However, I get the following error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" *Cause: *Action: Error at Line: 2 Column: 12 I don't see any problem in line 2 and the error is not very descriptive. It appears to be something to do with the as keyword. If I remove it, it works fine. However, I want my queries to be very verbose. Therefore, I must