SQL Using AS Operator
Tags: programming, beginners, sql, database
Published: 2022-04-08 10:01:50

---
canonical_url: https://baransel.dev/post/sql-using-as-operator/
---

> [Sign up to my newsletter!](https://baransel.dev/newsletter/).

## SQL AS Operator (Aliasing)

It is the SQL operator that we use to facilitate the use of long and difficult to use column names while making SQL queries and to make our work practical. With this operator we also get more readable tables. The point to note here is that we do not change the column names, we only use these aliases when displaying them to the user. So we do not make any changes to the tables. Let's show it with an example.

In our previous lessons, we created a database called `baransel` and a table called `students`. Let's show this table now.

```sql
SELECT * FROM students
```

<img alt="Students Table Structure" src="https://baransel.dev/post/sql-using-as-operator/students-table.png" style="height:75%;width:75%;"/>

If you pay attention, the column names can hardly be remembered and are not usable and also not readable. Now let's create easier to use and readable column names.

For this we will use the keyword `AS`.

```sql
SELECT name AS "Student Name" FROM students
```

<img alt="Students name as Student Name" src="https://baransel.dev/post/sql-using-as-operator/students-table-name-as-student-name.png" style="height:75%;width:75%;"/>

As you can see, we have shown the column named `name` with the alias `Student Name`. Are you going to say that we can only make one column one by one? Of course not, you can call the column you want with its alias.

```sql
SELECT name AS "Student Name", surname as "Student Surname" FROM students
```

As you can see, we called multiple columns with aliases. Another issue we need to pay attention to here is that we can no longer call all columns with the `*` operator. For this, we have to write them all one by one, let's do it right away.

```sql
SELECT name AS "Student Name", surname as "Student Surname", quiz, midterm, final, class_no FROM students
```
<img alt="Students Table with AS operator" src="https://baransel.dev/post/sql-using-as-operator/student-table-with-as-operator.png" style="height:75%;width:75%;"/>

In this way, we have called all the columns. If you notice here, the aliases for the ones we called with aliases came, while the other columns came normally.

## SQL Join Columns

Here, the names and surnames of the students are in different columns, but you may have seen that the names and surnames are used together in many places in daily life.

This is because it makes it more useful and readable. Now let's do it this way. Here again, the point we will pay attention to is that we do not change the table, we only convert it to data in a format that the user can understand.

```sql
SELECT CONCAT(name ," ", surname) FROM students
```

<img alt="Concat name and surname" src="https://baransel.dev/post/sql-using-as-operator/concat-name-surname.png" style="height:75%;width:75%;"/>

Thus, we have combined the two columns. But if you pay attention, there is no column name, you will ask how we will handle it.

```sql
SELECT CONCAT(name ," ", surname) AS "Full name" FROM students
```

In this way, we now have more readable tables. If we want to show all the columns then we have to write them all one by one.

> [Sign up to my newsletter!](https://baransel.dev/newsletter/).