table-alias

SQL - table alias scope.

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...

When to use SQL Table Alias

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 sho...

Table Alias in SubSonic

How can I assign alias to tables with SubSonic 2.1? I am trying to reproduce the following query: SELECT * FROM posts P RIGHT OUTER JOIN post_meta X ON P.post_id = X.post_id RIGHT OUTER JOIN post_meta Y ON P.post_id = Y.post_id WHERE X.meta_key = "category" AND X.meta_value = "technology" AND Y.meta_key = "keyword" AND Y.me...

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

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, * fr...

Does Squirrel SQL or Oracle have a way to alias table names in queries?

I'm using Squirrel SQL with Oracle. I often have to write quick queries for tables with longish names. It would be nice if I could give aliases to them and write queries like "select * from ft where n='blah'" instead of "select * from footablelongname where nameField='blah'". I wouldn't use that sort of thing in applications, but it wou...

What does "foo" mean in this SQL Server Query ?

for eg... SELECT * FROM ( SELECT RANK() OVER (ORDER BY stud_mark DESC) AS ranking, stud_id, stud_name, stud_mark FROM tbl_student ) AS foo WHERE ranking = 10 Here foo is present...actually what it does ?.. ...

Is there a way to give a subquery an alias in Oracle 11g SQL?

Is there a way to give a subquery in Oracle 11g an alias like: select * from (select client_ref_id, request from some_table where message_type = 1) abc, (select client_ref_id, response from some_table where message_type = 2) defg where abc.client_ref_id = def.client_ref_id; Otherwise is there a way to join the two subque...

MySQL: Possible to have wildcards in AS aliases?

I have a bunch of fields named the same across multiple tables (I inherited it - don't blame me ;). Instead of setting up all of the aliases verbosely, is it possible to assign/prepend an alias automatically by way of a wildcard? I'm envisioning something like (which of course doesn't really work): SELECT t1.*,t2.* as alias2.*, t3.* ...

Opinions: SQL Statements, do you use table aliases?

One of the guys I work with has the following to say about using SQL aliases, and he just posted the following on reddit. What do you guys think, to alias or not to alias? .... So I've always been the odd man out of my with my dev team about how SQL should be written. I learned in school to use aliases, but I hate them personally. I f...

How to identify fields from different tables with the same name in a JOIN query result?

Hi there, I'm running a query in MYSQL using LEFT JOIN to get users and their user groups. Both tables have columns named id. My result is being returned in an array (PHP) so that I have one array with all field data, but also only one array["id"]. Here's my query so far: SELECT usr.id, usg.id FROM users usr LEFT JOIN (user_gro...