In SQL, What Is the Letter After a Table Name in a Select Statement

In SQL, what is the letter after a table name in a select statement?

a is an alias for the table ADMIN

SQL Alias

What is the letter before or after a table name in a select/from statement in SQL?

The letter e is alias for table [HumanResources].[Employee] see https://technet.microsoft.com/en-us/library/ms187455(v=sql.105).aspx for details.

How to select from table all names that started on any letter - ORACLE

How to select from table all names that contains any letter?

You cannot use regular expressions in a LIKE comparison but you can use them in REGEXP_LIKE:

SELECT name
FROM table_name
WHERE REGEXP_LIKE(name, '[A-Za-z]')

If you want the column to start with a letter then anchor it to the start of the string:

SELECT name
FROM table_name
WHERE REGEXP_LIKE(name, '^[A-Za-z]')

If you want to output Great or Not Great then put it in a CASE expression rather than a WHERE filter:

SELECT name,
CASE
WHEN REGEXP_LIKE(name, '[A-Za-z]')
THEN 'Great'
ELSE 'Not Great'
END AS is_great
FROM table_name

What letters are written before column titles

The letters you talk about are referring to table names (or aliases).

Example using aliases would be:

SELECT c.customerName, o.orderNumber from Customers c 
INNER JOIN Orders o on c.id=o.customerid

Same query without aliases:

SELECT Customers.customerName, Orders.orderNumber from Customers  
INNER JOIN Orders on Customers.id=Orders.customerid

or omitting table names

SELECT customerName, orderNumber from Customers  
INNER JOIN Orders on Customers.id=Orders.customerid

The table denomination is specially important when you retrieve columns with the same name from different table. For example id from Customers and id from Orders

SELECT c.id as CustomerId, o.id as OrderId from Customers c 
INNER JOIN Orders o on c.id=o.customerid

SQL - how to select words with certain values at the end of word

You have to remove the last %, so it will only select words ending with es.

select * from table where Name like '%es'

SQL query, where name in column begins with a certain letter; clarification

If you are using SQL Server, you can do:

WHERE Name like 'M[a-m]%' 

However, a generate range, such as My-No, would be harder to express. You can always do:

WHERE name >= 'Ma' and name < 'Mn'

as well. This works for more complex ranges.

Select a Range of Letters

Select the names from 'A' up to, but not including 'E':

select ID, Name
from SampleTable
where Name >= 'A' and Name < 'E'
order by Name

As this is a plain comparison, it can use an index if you have one for that field.

Significance of random letter at the end of sub-query in FROM clause - SQL

SELECT sum(hr) 
FROM
(
Select sum(amount) as hr
from Try_again.dbo.tuesday_practice_database
where account_name like 'concessions'
union
Select sum(amount) as hr
from Try_again.dbo.tuesday_practice_database
where account_name like 'salaries'
) z

To understand better, look at the above version of your query. It's the same code, just reformatted to help illustrate what is happening. If you notice, the parent FROM clause retrieves data from a sub-query. In this context, SQL requires the subquery to have a name of some kind, and so the z is added as an alias to meet that requirement. You could put anything you wanted there, but since the name doesn't matter to us a single-letter placeholder is fine.

Just like the following query :

select * from table1 as z

By the way, you didn't use wildcard in your LIKE clause! I think you should re-write the query like below :

select sum(hr) from 
(
Select sum(amount) as hr from Try_again.dbo.tuesday_practice_database
where account_name like '%concessions&'
union all
Select sum(amount) as hr from Try_again.dbo.tuesday_practice_database
where account_name like '%salaries%'
) AS z

If you don't want to use wildcard, then you should avoid using LIKE Use IN instead and re-write to this simple one :

Select sum(amount) from Try_again.dbo.tuesday_practice_database 
where account_name in('concessions', 'salaries')

Selecting first letter of each word in a string in SQL

Please try the following solution. It will work starting from SQL Server 2017 onwards.

SQL

-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, col NVARCHAR(MAX));
INSERT INTO @tbl (col) VALUES
(N'John Doe'),
(N'Bob Dole'),
(N'Dan Roby'),
(N'Mary Smith Robert Polack');
-- DDL and sample data population, end

SELECT *,
(SELECT STRING_AGG(LEFT(value,1), '')
FROM STRING_SPLIT(col, SPACE(1))
) AS Result
FROM @tbl;

Output

+----+--------------------------+--------+
| ID | col | Result |
+----+--------------------------+--------+
| 1 | John Doe | JD |
| 2 | Bob Dole | BD |
| 3 | Dan Roby | DR |
| 4 | Mary Smith Robert Polack | MSRP |
+----+--------------------------+--------+


Related Topics



Leave a reply



Submit