I’ve been struggling with this problem. I have 2 populated tables and a third empty one and I would like to populate the third with data from the other two. Correlate values The idea is to assign every single ID from the 1st table to entries (several) found in the 2nd table that respect the condition wh…
SQL – Trouble counting values
I have a Database named ‘IDMS’ and it has two columns named ‘Table’ and ‘Column’. I Need to do a simple query, list the values in ‘Column’ with a count of duplicates. I tried this and not joy. I have tried differing variations of that select and it’s not w…
Select the duplicate rows with specific values
How can I only get the data with the same ID, but not the same Name? The following is the example to explain my thought. Thanks. Expected Output: How I have done. But the result included the following parts that I do not want it. Answer One approach would be to use a subquery to identify IDs that have multipl…
How to obtain row for minimum date for a value that is equal to the value in maximum date, per group?
I am trying to obtain row for a query.. where row value1, value2 in minimum end_date is equal to the max end_date, per group of id’s. My current query only obtains the row value1, value2 from the max end_date in the query result: This result obtains the most recent record, but I’m looking to obtai…
Alter a table which has non-unique non-clustered index to add a column
I have a table named Person which already have few non-unique non-clustered index and one clustered index (based on primary key). I have to write two queries: I need to alter the table to add column birthplace. Do I need to check any index while writing the alter table person add birthplace varchar(128) not n…
Update to replace specific value with another except when it already exists
I have a table with values like this: There’s also a UNIQUE constraint on both columns I want to change all ‘poo’ to ‘woo’, as long as it doesn’t violate the constraint, and then delete the remaining ‘poo’, in order to obtain this table: My attempts to far for t…
Default sort my own order without sort by
I want to leave the order as is in the in Clause, however SQL output is ordered by ID I know how to achieve the result using a temp table. Is there a better way to do it? Answer Not sure what you mean by I know how to achieve the result using a temp table as you haven’t shown
Knex join on column belonging to same same table
Using Knex.js, I am attempting to query a table of users. The only columns that are important for this scenario are internal_id (key), name, and supervisor_id. Every user (except one) has a supervisor and their record stored the ID of that supervisor. When viewing an individual user record in my app, I want t…
ORA-10400 error in PL/SQL, cannot auto generate tran_no field in table using procedure
T_Acc_Details is a table for storing the account number details of a person with the given fields. I have also inputted values into the field like the following: Secondly, I created the Transaction details table in which the values are to be inserted on the basis of it being deposit or withdrawal. The table q…
How can I UPDATE a table based on another table, using values from groups of rows?
I have two tables: I would like to update values in PTO’s WorkTypeId column: EMP NO in Employee (the lookup table) and PTO should match. A single WorkTypeId value should be picked from only the first occurrence of the month. For example, given this sample input data: TABLE Employee: Site WorkTypeId Emp_…