Skip to content

SQL – left join performs cartesian/multiplies matched rows

I have a very simple example but can’t understand why final result of LEFT JOIN returns 4 rows with value 3. Do I understand correctly that LEFT returns as many results for each row in left table as many matches it finds in the right table? (nb of rows times x nb of rows in right table). If yes, why

How to SUM two SUMmed SQL result fields

I have a simple table structure holding records of reagent_bottles and reagent_aliquots. Aliquots are created from bottles, and an aliquot record got a foreign key, bottle_id, to a bottles id. To get the total volume of a particular reagent (counting both the volume in the bottles and the volume in the aliquo…

How to find missing data in table Sql

This is similar to How to find missing data rows using SQL? and How to find missing rows (dates) in a mysql table? but a bit more complex, so I’m hitting a wall. I have a data table with the noted Primary key: I have a products table with all products, a countries table, and a calendar table with all

Executing view within a stored procedure

Is it possible to execute a view with a stored procedure? My procedure should first run the views (I have 2 in total) and then am combining these 2 views data into a different table for applying transformations. Something like this: Answer What do you call “execute a view with stored procedure”? H…

Add one year to age based on date BigQuery

I have a table containing birthday information: I’m trying to calculate the current age but only want to add on a year when the date is 12-01. For example the first row was born in June, 2016. The current age should be 3.5 and come Dec 1, 2020 the age would increase to 4.5. So I only want it to