Skip to content

Tag: sql

SQL Server: How to flatten nested arrays by merging values using

I have 10000 jsons with different ids each has 10000 names. How to flatten nested arrays by merging values usin SQL Server? Jsons can be read in any language, I’m looking for any SQL dialect that can transform the data as I’m using spark connectors. I use many SQL dialects including not limiting S…

Create a Month function

I would like to run a query that runs monthly but it will check daily if the timestamp from the records is from the previous month. If yes then it will run the query and append to the previous monthly data. So, I want to create a simple function to return TRUE if the RecordTimestamp is from the previous month…

SQL good practices: should I use associative tables in this example?

I want to link two tables: a “company” table and a “branches” table. I find two ways to do it: Method 1: Method 2: In practice, I think that both ways work the same, but professionally speaking, I think Method 2, using associative tables, would be the proper way to do it following SQL …

Translating Oracle Date Functions to BigQuery

I’m having trouble translating these Oracle date functions to BigQuery because BigQuery doesn’t allow such user-friendly additions to dates/timestamps. Any help is appreciated. Below are the two date functions in Oracle and my attempted (failed) versions in BigQuery: Oracle: BigQuery attempt: Answ…

Why does this inner join of two tables create duplicate rows

I have the following tables: Users Conversations Group_Members I need to select all the conversations where a user with a specific ID takes part in. Users and Group_Members are in a many-to-many relationship. Why does the following query create duplicate rows on the last select, as seen in this image? User.Id…