Given the following (simplified) tables: If I run the following query to get which posts a user (?) liked: Would the RLS policy for SELECT on the likes table and posts table both be invoked, or would it only apply to the posts table since that is where we are SELECTing FROM? I’m under the assumptiom tha…
MySQL select unique records from one table with two select queries using NOT IN
TaskNumber JobNumber Status Date 11111 JS0001 0 04-06-2021 11112 JS0002 0 05-06-2021 11113 JS0003 1 05-06-2021 11114 JS0001 1 06-06-2021 Table Tasks. TaskNumber is the unique id(primary key). Status 0 is not done, 1 is done. example: JobNumber JS0001 assigned on 04th of june and not done, so reassigned on 06t…
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…
How to add date to a file’s name using UNLOAD in Redshift
I found 2 solutions: Using AWS Data Pipeline to schedule the query (Unload) and use ‘s3://reporting-team-bucket/importfiles/test_123-#{format(@scheduledStartTime,’YYYY-MM-dd-HH’)}.csv’ writing an MV command to rename the file on the s3 bucket Is there a way to give a file’s the c…
How do I replace blank spaces with null values and query where values are not null? (I’m filling in a table)
I have two tables: table1: USER_NUM FIRST_NAME LAST_NAME A123 Billy Bob A124 Billy Joe Jane Doe John Doe I am trying to insert FIRST_NAME and LAST_NAME under USER_NAME into table2: OWNER_ID USER_NUM USER_NAME 111 A123 112 A124 Using this query: The problem is, if I isolate my select statement I still get blan…