Skip to content

SQL – Select from Multiple databases

I have 10 databases all in the same instance and schema with identical tables. Looking to create a SELECT query which can use a variable of the database names and return all of the records into a single dataset. I’ve been looking around and put the following together as a test (the real select statement…

Postgresql : Query were each join result is a line

I got a database structure with three tables. On table containing some ids and two table containing the same row and a foreign key on the first table : How to get a result looking like this (a kind of left join were each result is displayed in lines instead of in additional columns in the result): Answer I th…

SQL Insert into with join and where

I have three tables. For example: newTable: oldTable: associativeTable: What I want to do now is: I want to move the name column from oldTable to newTable. I have already altered newTable and added an empty name column. Now I’m trying to write a correct INSERT INTO statement. What I have so far is: I&#8…

Checking for different columns OR empty result PostgreSQL

I’m writing some query tests for dbt and I’d like to check that two queries return the same thing and that neither is empty. Since it’s a dbt test, I need to return a row if either of these conditions is false. So far I’ve come up with the following: Theoretically, this should return a…

Remove specific value in a string with SQL or grafana

Displaying some data using free version of grafana. The string that has to be displayed looks like this: 5555.7777, but I only want to display 5555. Are there any functions to remove .7777 in SQL or grafana, so that the value that will be displayed only looks like this: 5555. Thanks in advance. Answer You sho…