I’m using SQL Server and am trying to add a column and a check constraint. I’ve found that the following works: However a less verbose way of writing this does not work: The following error is output: Column CHECK constraint for column ‘isTrue’ references another column, table ‘t…
Tag: sql
How do I select all columns that belong to one columns MAX() value in SQL?
I need to get values from different columns (in one record) where one column has a maximum value. How do I select the maximum value of one column and all the other columns from the same record? This only selects the highest value of the selected column Answer I can’t comment on other posters answers yet…
SQL file executes with no error but also no results through shell script
I have a sqlfile that I want to run via shell script against an Oracle pluggable database. The sql file basically just loops through table names to apply grants to a role. When I run the script, it looks like it executes the file, but it really doesnt, no grants are applied. When I log into sqlplus and execut…
How to combine columns, group them then get a total count?
Below is a table that has candidate_id, two interviews they attended with the interviewer’s name, and results for each interview. candidate_id interview_1 interview_2 result_1 result_2 1 Interviewer_A Interviewer_B Pass Pass 2 Interviewer_C Interviewer_D Pass Reject I need help to combine column intervi…
MS SQL Server view with conditional values
I have a table A that can reference to itself to inherit some values from a parent. The reference is represented with ParentID. Parents have null values in ParentID. ID ParentID Field A Field B Field C 1 NULL ValueA1 ValueB1 ValueC1 2 NULL ValueA2 ValueB2 ValueC2 3 1 null ValueB3 null 4 1 null ValueB4 null 5 …
SQL query to get values by the calendar month
I have the following schema: and i want to get a return object that has the industry id along with the number of items but based on the calendar month for the previous two months, not including the current. So i want the number of items in October and the number in November. What i have, that is not working
Optimize nested inner joins
The following TypeORM generated SQL query takes over 11 sec to complete : Given the following database indexes : It feels like some left joins could be indexed, but I am unsure how to do it the proper way. Besides from indexing, is there anything I could do from TypeORM (or other), to really speed up the requ…
Is it possible to use a SELECT statement inside a CONCAT?
I’m trying to create a string from table values, along with some text to make it more readable. The only problem I’m having is that I can’t get the SELECT statement to work inside my CONCAT. It’s been bugging me for quite some time now, and I would appreciate any feedback on what IR…
How to join multiple tables and printing the result for same id which are populating more than one in a single row
The problem facing in joining the tables : Table ques_ans has ref_ques_id column that is being populated from ques_ref table. So, If ref_ques_id = 3 and ref_ans_id = 1 then it should display ‘Yes’ i.e populating from ans_ref table. Likewise for ref_ques_id = 2 then it should display ‘No̵…
How to let user only delete their details and no one elses php
I created a very basic site where a user logs in and then has access to a table that they can edit. I want the user to be able to only delete their own details and no one elses, and I don’t know what i’m supposed to add to the delete page so it only deletes the details of logged