I’ve searched but can’t find an answer to this one. Any help would be appreciated. I’m running a select statement joining to columns which returns some results but I then want to return the value from one column based on the minimum from another column. Heres what I wrote to get the first se…
Tag: sql
SQL CASE with CASE
I have a CASE stmt within CASE and the code is something like below: I need to achieve below condition But below code is not working. Can anyone correct this code? Here If mgmt.id IS NOT NULL then status_fl should be set as ‘Y’, and If mgmt.id IS NULL then we need to check the condition If staff.N…
SQL selecting date by month and year but select another month/year rows by column relation
I have the following example in my database: workshop_class_id workshop_session_id workshop_class_date 209 29 2021-06-20 210 29 2021-06-21 213 31 2021-06-30 211 30 2021-06-30 214 31 2021-07-01 212 30 2021-07-03 219 33 2021-07-12 I would like to select by month and year, for example June 2021, but if the rows …
SQL row value expression with null failing in where-in query
I am struggling to understand why this where-in query is failing when there are nulls in the row value expression. The query is not returning a single record from the below table. I expected each row value expression to match exactly one record. I appears the null spoils the fun and I don’t understand w…
Define enum as the column names of table PostgreSQL
Is there a way to define an enum using a table’s column names? I have a users table defined as follows: And then I want to define a required_profile_fields column in another table to be an enum containing only the column names in that public.users table: Is there a way that I can define that profile_fie…
Is it possible to fetch and compare an element which resides in a nested Json string format column in database? Via SQL Query
I have ‘a unique-id’. I want to fetch records from table on basis of that unique-id. I have a column named “request body” that contains a nested json string which is of type text. Is there any way i can compare ‘unique-id’ with the ‘unique-id’ inside the json st…
MS Access SQL query – Count records until value is met
I have an Access query (qr1) that returns the following data: dateField stringField1 stringField2 booleanField 11/09/20 17:15 John Nick 0 12/09/20 17:00 John Mary -1 13/09/20 17:30 Ann John 0 13/09/20 19:30 Kate Alan 0 19/09/20 19:30 Ann Missy 0 20/09/20 17:15 Jim George 0 20/09/20 19:30 John Nick 0 27/09/20 …
What are the downsides of making a numeric column a string in a database?
I have members on my team who are tossing around the idea to make every column in the database a string including numeric columns. I know that sorting becomes an issue. What are the other downsides of making a numeric column a string? Answer The major issue is that users can put broken data into the columns &…
Percentage increase/decrease reading 9% as 90% when putting it in descending order
I created a new column called ‘Percentage’ that calculates the percentage increase between Expected and Actual payment. The calculation seems right but when I put it in descending order, 9% is right below 90% when 9% should be at the bottom of the list. In addition to this, i’d like to remov…
How can I make my sql trigger about inappropiate words work
I have a database with different tables in order to store photos, users, reviews, ratings… I wanna validate that no one uses “bad words” (insults) in their photos’ title or description. So I decided to create a table called ‘inappropiatewords’ where all of these bad words w…