Questions tagged [alias]

Within a query, tables or subqueries may be aliased for readability and so that the same table can be referenced more than once in the query with different join conditions.

Filter by
Sorted by
Tagged with
1
vote
0answers
29 views

Postgres - want a database to have two names

One of my Postgres databases is named entirely in upper-case, and a new bit of software needs to see it in lower-case. I've tried renaming it, but unfortunately that breaks the huge multitude of ...
2
votes
0answers
39 views

CNAME alias from named SQL instance to default instance [duplicate]

I know I can use CNAME alis to point from one SQL Server to another for upgrade or such log shipping, but what if one is named instance and other is default instance? Do I need SQL alias? Do i need ...
0
votes
1answer
23 views

Why do I get an error when filtering subSelect?

select "masters".*, (select avg (rating) from "reviews" where "master_id" = "masters"."id") as rating from "masters" where rating > 3 [42703] ERROR: column "rating" does not exist
1
vote
1answer
150 views

SQL Server 2012 - Create Alias from default instance (i.e. '.') to named instance of SQL 2012

Scenario is: I have SQL 2012 running as a named instance 'SQL2012'. I can connect to this via SSMS using '.\SQL2012' Working on a new project, I now want this named instance to be accessible as '.' ...
3
votes
1answer
1k views

Using column alias in a WHERE clause doesn't work

Given a table users with two fields: id and email. select id, email as electronic_mail from ( select id, email from users ) t where electronic_mail = '' Postgres complains that: ...
0
votes
1answer
57 views

Is it possible to tell if an incoming connection is using an SQL Server Alias?

Using SQL Server Configuration Manager to Create a Server Alias for Use by a Client is cool tool used in many cases when it works In my DBA position I do not have access to the application server, to ...
0
votes
3answers
773 views

How to use column alias to calculate other column value

My query is SELECT (`house_rent`+`conveyance`+`medical`+`dearness`+`others_allowances`) AS earnings ,(`income_tax`+`pro_tax`+`emp_state_insu`+`absence_fine`+`others_deductions`) AS ...
5
votes
3answers
282 views

Getting SQL server to recognise a date column

I am trying to get a count of IDS on a orders table for yesterday (not hardcode) where the date in the table corresponds to when the order was placed. My table looks like this orders ( order_id INT ...
1
vote
1answer
115 views

SQL Server Upgrade - A new Approach for Upgrading

Microsoft's technical guide for SQL Server upgrade references two upgrade paths: in-place and side-by-side. I don't see a third, visibly more viable/convenient option, which is to do an in-place ...
5
votes
1answer
632 views

Same table alias for two different tables (Oracle)

This example has the same table alias used for two different tables. I don't understand why this is allowed by Oracle, and if allowed, how the results make any sense. create table Table_A (x number);...
1
vote
1answer
2k views

Two joins on same table in SQL

I've got 2 SQL tables: NAMES and RELATIONSHIPS Currently NAMES just has 2 columns: name and name_id. The other is a list of relationships between people in the NAMES table. It has 3 columns: ...
1
vote
1answer
3k views

How to create a view from a join with multiple duplicate column names?

I have a few tables with this sort of format myTable: id | Table1_id | Table2_id | Table3_id | value Table1: id | text | ... Table2: id | text | ... Table3: id | text | ... I want to create a ...
1
vote
4answers
114 views

Is there a valid reason to alias a column to the exact same name/case?

I inherited some code like this: SELECT Col_1, Col_2 Col_2, Col_3 ... Does the Col_2 alias actually accomplish anything, or is it completely unneeded?
1
vote
1answer
780 views

Conditional Alias in SQL

Is there any way to give conditional alias to SQL columns?. Because I have two tables for Fields and Category. Meaning of each field changes conditionally. DECLARE @f1 NVARCHAR(10); set @f1= (...
6
votes
3answers
690 views

Display column title as in the query without 'AS' statement

I query data from multiple tables using JOIN statements like this : SELECT u.id,u.name,d.id,d.name FROM user u RIGHT JOIN dog d ON... ; When I get the answer, in psql for example, I've got this kind ...
0
votes
1answer
113 views

Data from Same Column Joined in Two Different Ways

In the following sybase query I would like to pull the vendor column twice: the first time I would like to pull the vendor associated with the ReceiveWorksheet table by associating it with a key ...
0
votes
1answer
91 views

How to easily show very long “canonical” name for each column in all reports?

Related: Does the length of a table name affect performance? For query writing purposes I want to have nice short actual column names. However, from my actual data source, I have an extremely long "...
3
votes
1answer
494 views

Why is the 'AS' table alias keyword required in Visual Studio (Database projects)

Up till now I have been working directly on SQL Server instances, and am now playing around with how best to keep databases in source control. The visual studio database project seems to be exactly ...
-1
votes
2answers
6k views

For a query can you have a two word alias

What I want to do is SELECT COUNT(CustomerID) as CC as 'Customer Count', Country FROM Customers GROUP BY Country HAVING CC > 5 ORDER BY CC DESC; Which is wrong. What is the right way? From: ...
2
votes
1answer
642 views

ORDER BY clause with Alias

I am trying to get the sum of the market values for each given CPTY. Each CPTY can have several market values. In my output list, i want to see the top 5 CPTYs, ordered by the sum of their market ...
3
votes
1answer
1k views

INSERT INTO with UNION Alias ERROR

This question is derived from the following post UNION query not working Fails: INSERT INTO AssetControl SELECT * FROM CSVImport UNION SELECT * FROM AssetTemp; Works: INSERT INTO ...
6
votes
1answer
488 views

When are COLUMN aliases in FROM clauses needed?

FROM provides column_alias, the SQL spec calls these <derived column list> clauses. This is what the postgres docs say about them, A substitute name for the FROM item containing the alias. An ...
0
votes
0answers
320 views

Is there any way to set the alias for command permanently in PostgreSQL?

I'm trying to set the alias for command permanently in PostgreSQL. I've set the alias for a command like given below. Test=> \set x '\\! reset' So, the alias has set for reset the terminal. While ...
5
votes
1answer
1k views

Column alias in Postgres FROM clause?

I'm reading through the Postgres documentation, the page on SELECT statements, and I ran across an aspect of aliases that I have never encountered. In the section on FROM clauses, subheading alias, ...
0
votes
1answer
101 views

SQL Server Change Alias Not Recognized in SSMS

I created an alias named "ProductServer" to point to a SQL Server 2008 R2 named instance on my local machine. I'm trying to upgrade that to point to SQL Server 2014 named instance. I used SQL Server ...
2
votes
2answers
1k views

DB2: Database alias already exists when cataloging

SQL1005N The database alias "XYZ" already exists in either the local database directory or system database directory I am an accidental DB2 LUW on linux administrator; primary background in MSSQL ...
1
vote
1answer
685 views

DB2: Column-Aliases with Line-Breaks

Using DB2 9.7, is it possible to produce a result set where the column-headers contain line-breaks? Something like: select field_name as "Line1<br>Line2" from table_name I want the column-...
2
votes
2answers
2k views

Alias for multiple instances on a SQL Server

I have 2 SQL named instances on a SQL Server, trying to add aliases for both so that application teams can use the alias names in their connection strings. There are 2 IP Addresses assigned for the ...
1
vote
1answer
5k views

Joining two tables with an alias

I have the following query which casues some problems: it complains that ORA-00904: "TLEA"."TLSN_TRD_ID": invalid identifier even though TLSN_TRD_ID is clearly in the TLEA table. It is as if the ...
1
vote
1answer
27 views

I have a query which does not return result with the desired alias names of columns in PostgreSQL

The following is my query which does not return result with the desired alias column names: with d as (select distinct emp.ahrims_id, rank.name as rank from hr_employee as emp, ana_rank as rank, ...
1
vote
2answers
138 views

Referencing a SELECT subquery value in the WHERE clause

Complete query SET @vSelect = ' SELECT T1.BranchShortName AS BranchShortName, ( SELECT TT1.EmployeeName FROM [dbo].[...
5
votes
3answers
1k views

How and when do I use an alias in my SQL statement

I have a query in which I do some calculation and then I give that column an alias. In the next column I would like to use the result of that calculation in an IF statement. MySQL did not recognise ...
3
votes
2answers
566 views

PostgreSQL requires “GROUP BY” when aliasing a table?

Here's something strange: there is a large table named "products" which is partitioned with inheritance such that there are two children: products_active and products_inactive, and the constraint is ...
0
votes
1answer
7k views

how can I use a CASE with an alias defined befor case?

how can I use an alias like pop in a further case like in this example (Oracle database). select (select sum(ccs_pop) from rap4) as pop, case when pop+x=a+b+c then pop+x end as sum1, case ...
0
votes
1answer
493 views

MySQL views performance for alias purposes

So I'm working on a Rails project and I have a legacy database, that is used by other applications, hence its structure cannot be modified. The problem is that table and column names do not follow the ...
0
votes
3answers
104 views

Major performance difference from a small change in query

I have a query written out to search a WordPress database for any post ids that match the keyword search to post content, title, author, or associated company. The company portion of the query is ...
2
votes
1answer
4k views

Aliases in calculations for MySQL

I am in the process to move a really small database from Access to MySQL and I have some queries to translate. I have this really simple query (in Access db): SELECT InvoiceNumber, Field1 + ...
4
votes
3answers
17k views

Use column alias in GROUP BY

I have a query where I chain two columns. Why does the alias not work in the GROUP BY clause but in ORDER BY clause, it does work? How can I write the select correctly? SELECT KOS_VER_ID AS "...
5
votes
2answers
280 views

Why do so many queries have aliases? [closed]

I've spent a lot of time searching for, researching and implementing various complex MySQL queries over the last several years. Many of them use lots of aliases for tables, even when none are ...
0
votes
1answer
429 views

Can alias in SQL Server contain slash?

I'm not sure if there is such a question that I can't seem to find. I have a clustered instance named FC\SQLSRV. Because this is the virtual name so I can't create an alias for the clustered instance. ...
3
votes
4answers
1k views

Mysql Order By affecting a Query with column alias, group by, and having

Description: I have a query with column alias, group by and having. It's getting altered when I add an order by. This strange behavior is only happening in 5.6.16 and 5.6.21 (which I was using in ...
0
votes
1answer
325 views

Why can't I use a cname/alias in the permissions table?

At work we have a usual setup with web server(apache) and database server(mysql). From time to time there is the need to migrate the web stuff to a new server. Lets say their a records are dull and ...
1
vote
1answer
2k views

Alias of Subquery not working

I have been trying to get an order by to work correctly with an aggregate function. i.e. order by (bp + points) I also try adding these as a total amount from the following query however. If I try ...
0
votes
0answers
992 views

Is it possible to alias a column with a constant variable defined in the package header of a PL/SQL package?

I am trying to alias some columns that are being used to interface with a 3rd party data aggregation system. This company has stated that they might change their naming scheme in the near future, so I ...
0
votes
1answer
1k views

Performance hit with column alias

I have a database in SQL Server 2008, with the final data table having about 2 million rows. The development team is implementing a new application and they have suggested changing the column name to ...
2
votes
1answer
1k views

Aliases with correlated subqueries

I am looking at an example of correlated subquery with aliases from a PostgreSQL book: bpsimple=# SELECT * FROM orderinfo o, bpsimple=# (SELECT * FROM customer c WHERE town = 'Bingham') c bpsimple=# ...
0
votes
4answers
10k views

How to find the same salaries and department names?

Write a query to display last name ,department number,and salary of any employee whose department number and salary both match the department number and salary of any employee using the following ...
0
votes
1answer
370 views

Need to find the employees who have switched jobs atleast twice

I am trying the following query on the tables which are described below: SELECT * FROM job_history INNER JOIN employees ON job_history.employee_id = employees.employee_id WHERE employee_ID IN (...
1
vote
2answers
132 views

How do I add an alias to the table

SELECT MAX(COUNT), A.id FROM ( SELECT supplier_id as id, COUNT(*) AS count FROM `library`.`lms_book_details` GROUP BY supplier_id ) GROUP BY A.id; While executing the query, MySQL gives ...
2
votes
2answers
12k views

Select * on inner join with common columns

I have 3 tables (mysql db) on which I want to do an inner join. The problem is that these tables have common columns. I know I could use aliases to differentiate them (select A.x as Ax, B.x as Bx, C.c ...