Skip to content

Tag: sql

Match column name with data from other table

I have dynamically created a temp table #temp1 that create column dynamically based on a json string. The table will look like as below #temp1 ID Field FRUIT VEGE 1 Field1 A B 2 Field2 C D I would like to fill in the value column only in result table based on the #temp1 table, the field and type_id is

Postgres not returning data on array_agg query as below

The problem arise when there are no data for books in specific library. Consider a following working scenario. Table name: library Table name: books Now when I do query like below: The query generates output for library 1 & 2, but not for library 3. Why and how to solve this issue? (Generate an empty list…

LOOP/FOR statement on oracle script

I’m running an ansible playbook that runs an sqlplus script to an Oracle DB. Basically the script creates a CSV file with some server info. The query is pretty much autogenerated, so it will be difficult change it. The problem is that this query brings all the 5000 server and I need only 200. I want to …

Consolidate SQL Union With JOIN

Let’s say I have 2 tables (bar_helper and bar). I have a query that retrieves records based on a JOIN between the tables and some condition. Essentially, my first result set is joined and I want my second one to be unconditional and just based on one table. This works fine. However, now I need to also g…