I was trying to change an update statement where there is a subquery in the WHERE clause to a join in order to improve performance. DDL to sample table/data CREATE TABLE [dbo].[Table1]( [pre_plan_id]…
Tag: subquery
I need a Row_number over partition to achieve this in SQL Server
I have three columns PID, AppNo and ProcessedDate I need a query to update the AppNo in the format below PID AppNo ProcessedDate 11 1 09/30/2019 18:21 3 1 09/25/2019 08:37 3 2 …
How to convert a query into a nested query
How do I change this query into a nested query? The query and tables are listed below. tables goes as follows Nation : N_NATIONKEY, N_NAME Supplier : S_SUPPKEY, S_NAME, S_NATIONKEY Customer : C_CUSTKEY, C_NAME, C_NATIONKEY Orders: O_ORDERKEY, O_CUSTKEY Lineitem: L_ORDERKEY, L_SUPPKEY, L_QUANTITY, L_EXTENDEDPRICE, L_DISCOUNT Answer I’m not sure exactly what kind of nested join you’re looking for, but here is
Error: ‘duplicate key value violates unique constraint’ even when checking with ‘where not in’
I get the error: ‘duplicate key value violates unique constraint’ even when checking if the primary key is already in the table in which I want to insert. I have tried to check with either ‘where not y.a in…’ as well as with ‘where not exists…’ The code I use right now is the following: This above code returns the
Select Min Date value from subquery to main query
I’m trying to get the min Date value as a column in the main query where the main query & the subquery have inner joins & the min Date value is dependent on grouping of 3 columns from the main …
MySQL Grouping using group_concat and then Group BY
I have a table like this: Basically, I want to group all names and give the count of such groupings like: Since there are 2 users with cooking and cleaning, 1 for washing and 4 for cooking. I am …
PHP and Mysql, avoid multiple loop queries
I have a table myTable that looks like this: +——-+——-+——–+————+ | Id | Agent | Qualif | Date | +——-+——-+——–+————+ | 1 | A | Q1 | 2019-05-…
How can I “Update Select” some values in a column with a subquery?
I am using Apache Derby DB (SQL) version 10.14 and this is the Derby Reference Manual: https://db.apache.org/derby/docs/10.14/ref/refderby.pdf I am trying to create a star schema and am currently …
Struggling with correlated subqueries in SQL
I have a database about old cars, their owners, events and the attendants of those events as such: Image of tables used : PK: Primary Key FK: Foreign Key Now I need to get the amount of different …
select columns’ values based on another two values from another column
I have this data set and I need to extract multiple columns values based on on column value. To elaborate on it, I have a rental table, inventory table, customer table, and I want to relate customer …