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.

--

--

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

95 Followers

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/