I have a table: If clients feedback than 1 otherwise Barbers feedback 1, how to make a constraint for this situation? ClientFeedback bit null, BarberFeedback bit null, Sorry for English Answer You use a check constraint. For instance, if you want exactly one value to be 1: I am guessing that might be what you…
Tag: sql
How to split a sentence and get only left 15 or less (Not greater than 15) characters on one column but at the end it could be a complete word
How to split a sentence and get only left 15 or less (Not greater than 15) characters on one column but it could be a complete word. Example: Ali, House Number ABC/123, Sattelite Town, Lahore. Need support here. Answer You can try something like this:
How can I use ORDER BY column_string like column_int when my column_string have letters?
I have a table like: —————— | ID | Animal | —————— | 1 | B1 | —————— | 2 | B2 | —————— | 3 | B3 | —————— | 4 | …
Psql query : Union is not preserving the order of rows coming from cte
I have this query: cte1 is ordered by salary column but cte2 is not. I want the results of cte2 to get appended to the results of cte1 while preserving the order of results from cte1. But it’s not happening. If I run the above query without union with the second cte, the results are displayed in the exp…
(SQL) Pulling linked profiles from two tables using Knex
I currently have two tables with the following data: I currently have my query set up like this with Knex: I’m currently parsing the data into the following format: This works totally fine except for the cases where the parent has no children, as it won’t pull any data at all, including parent inf…
How do I return NULL conditionally from a JSON_QUERY
How do I return a JSON_QUERY that returns NULL (or no property at all) if the selected value from the sub-query (or left join) is empty? Here is a simple example (imagine NULL below is a sub-query): This returns and empty JSON object – which is not what I want: Since NULL is being returned from the sub-…
Select from cross tables in postgres problem
Lets imagine i have a table A that contains rows X,Y and Z, and i have another table that relate elements from A to another table B. A_B : element_A, element_B, and i want a query that for element b in B returns for all elements a in A return True if {a, b} exist in the table A_B and
MYSQL no duplicate of 2 values
I couldn’t find an answer for this exact question although I am sure the information is on here somewhere. I have a python script that is adding stock data into a database. For each stock database has ~1000 lines where ‘ticker’ is the stock name and ‘time’ is the date(1 for each …
Logic for backward updation based on parent value
I have below tables with data as below Table_Cell Table_column Table_row I need to update SwitchCol in Table_column and Switchrow in Table_row Logic is If for an column_id in Table_column, all the combination with row_id in Table_row,present in table Table_Cell is 1, then make the SwitchCol =1 for that column…
SQL: How to select two employeeid within same team and have a team_score greater than 400 ? Mentioned the table schema below
Previous_teams id (integer) name (text) team_score (real) Team_members team_id (integer) employee_id (integer) employee_name (text) birthday (text) popularity (real) Q: How do I select a pair of employee ids that have worked in at least 5 prior teams where the (average)team_score was greater than 400 and coun…