DEV Community

Cover image for Simplified SQL: Harnessing the Power of Aliases
Markme Dev
Markme Dev

Posted on

Simplified SQL: Harnessing the Power of Aliases

Hello there its me again,

So by now, you know what this is all about. But let me clarify once again that we are now going to discuss SQL aliasing for better readability and cleaner queries. It's helpful to use aliases if the names of your tables or columns are too long. We can use aliases for column names, tables, subqueries, and so on, but we'll focus on table and column names since this is more basic and easier to understand. and it also good to use alias if you are going to combining column.

Here's the example of query that no alias.

Image description

As you can see, there is a '?' column. This signifies that we combined the tables, but the SQL engine couldn't determine a name for it, hence the default '?column?' in the SQL column.

This one is the revise version

Image description

We add an alias to the combined column name so that it can be given a column name. This is just one example of how aliases are used. We use aliases in table names, subqueries, etc., as I mentioned earlier. However, we're not discussing those uses now because we're focusing on the basics. We may explore those topics later, but it's important to grasp the fundamentals first.

Now that you know what is alias is try to apply it in your query and see the improvement. I hope you learn from this blog , Thank you so much again and good day.

  • The data that I'm using here is just dummy data sourced from DataCamp, so there's no need to worry, guys. MARKME

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay