I know that this question has been already answered a million of times, but I couldn’t find any solution. Well I have these three tables on postgres sql. When I try to create the table incident_has_volunteer it throws the error there is no unique constraint matching given keys for referenced table ̶…
SQL using If Not Null on a Concatenation
If I have the table SELECT (Firstname || ‘-‘ || Middlename || ‘-‘ || Surname) AS example_column FROM example_table This will display Firstname-Middlename-Surname e.g. John–Smith Jane-Anne-Smith …
Spark SQL passing a variable
I have following Spark sql and I want to pass variable to it. How to do that? I tried following way. Answer You are almost there just missed s 🙂
Select certain column only if condition met
I want to have a select that will not have fixed number of columns. Column OptionalColumn should be selected only if variable @check = 1 This is what I had (syntax is bad but maybe it explains my problem) It is crucial to have it only if @Check = 1 and not having it if @Check = 0. Is it
MySQL: How to convert seconds to mm:ss format?
I want to convert seconds to minute : seconds format in sql select statement. At the moment I am using: It works perfectly but it gives me this format of time: hh:mm:ss but I need mm:ss Is it possible to convert seconds into mm:ss format using sql query? Answer If the value is less than an hour, then just do:
How to implement and insert value SQL specialization/generalization
I have my table with these 3 entities: student, lecturer and person. Person will be the parent that holds common attributes of student and lecturer. This is my database design, is this a correct way …
SQL Updating column after adding it giving “Invalid column name” error
I have the following SQL in SQL Server 2005 but I get an error stating “Invalid column name ‘ExpIsLocalTime’ (ln 7) when I run it: IF NOT EXISTS(SELECT * FROM sys.columns WHERE Name = N’…
Update and insert to one table from another
I have two tables: table1: (ID, Code, Name) table2: (ID, Code, Name) with same columns I want to to insert data from table1 to table2 or update columns if that exists in table2 (table1.ID = table2.ID) What is the simple way to do this? WITH OUT MERGE Answer There are some issues with Merge statement,so it sho…
How to decide which fields must be indexed in a database table
Explanation I have a table which does not have a primary key (or not even a composite key). The table is for storing the time slots (opening hours and food delivery available hours) of the food shops. Let’s call the table “business_hours” and the main fields are as below. shop_id day (0 R…
Checking if a value exists in sqlite db with Go
I’m writing code to manage users in a sqlite database with Go. I’m trying to check if a username is taken, but my code is ugly. My table looks like: And I check if a username is taken with: Is there a better query I could use that would tell me if the username value exists in the table in