SQL Code Analysis

SQL Query

Sample SQL query
  1. The table names aren’t descriptive of the data they hold.
  2. The example query uses the exhaustive column retrieval method, which can be very expensive and cumbersome over tables with a larger number of columns, especially when you need to select only a few columns.
  3. If the two tables don’t have too many matches on the keys selected, the merged table retrieved will have a high proportion of zero values.
  1. The names “a and b” should be replaced with a name that describes the kind of data in each table.
  2. If we only need to select a few columns, it’s better to list the columns rather than using “a .* and b.*”.
  3. After studying the code carefully, I think an INNER JOIN would do the job more efficiently and effectively than a FULL OUTER JOIN.
  4. If all the table columns must be selected, a better alternative to the original code example would be to use a single “*” to retrieve all the data from both tables as shown in the code block below:
Improved Version of SQL Query.

--

--

--

Data Scientist and Technical Content Writer. Looking to inspire the world and deliver value — one step at a time. https://www.linkedin.com/in/abseejp/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Create and Deploy a FastAPI Application Using Poetry and Serverless

The Known Unknown: Working with Option and Nullable Types

How to Create a Free App and Make Money

Approaching Data as an Enterprise Asset

How to Install Graylog On Debian 7 The Right Way Full Tutorial

How to Build Java Applications Today: #58

Mastering Android Themes — Chapter 4

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abraham Enyo-one Musa

Abraham Enyo-one Musa

Data Scientist and Technical Content Writer. Looking to inspire the world and deliver value — one step at a time. https://www.linkedin.com/in/abseejp/

More from Medium

Data Definition and Constraints in the CREATE statement in SQL

Rewriting Window Functions with Joins in SQL

All about SQL joins

Basic SQL Concepts Query Strategies