Skip to content

Pivot with changed structure of the final table

I have the following table – How do I write a query to produce this output – The output table is a connection table between all the columns in the input table. For example, if the value in column A <> column B in the input table then insert a record in the output table. If a value in column

Sql data in multiple rows – get output in one row

I have a table in sql which looks like below. Basically typeid column determines which type of data it is like address, name, department etc. So, there are multiple rows in the table for one employee. table ID employee Type id column 1 column 2 column 3 1 1 5 building 6 null New York 2 1 6 Adam Smith

Flyway does not insert values to database

I added flyway library to my spring project. I configurated it and wrote some instuctions, project compiles but flyway does not insert values provided into data base. Config of application.yml: Impl: [ressource folder] SQL instructions that must be insert: But after running application, they dont figure in da…

SQLBolt.com – Alternative Answer to Lesson 8, Q2

I have an alternative answer to the 2nd question from Lesson 8 from https://sqlbolt.com/lesson/select_queries_with_nulls Find the names of the buildings that hold no employees My attempt is: SELECT building_name FROM buildings WHERE building_name NOT IN(SELECT DISTINCT(building) FROM employees); It’s no…

Speed up joins on thousands of rows

I have two tables that look something along the lines of: And a query to get data from t1. The query runs fine and takes a few ms to get data from it, although problems start appearing when I use joins. Here’s an example of one of my queries: Which can return a few thousand rows, that might look somethi…

How to select part of the CLOB column with SQL

I am trying to get part of data from CLOB column which contain XML. I need this because I want to create a report based on this data. Table structure: DIAGRAM ( ID number, XML clob ); XML example: I want get this results: Thanks in advance! Answer The main problem is that your XML is invalid. It’s missi…