I am trying to transform the current format I have my data in 1 into the format of image 2. As you can see the data is currently split over two rows per one cust_id for each code they have but I want …
Sorting and Number results based in order, using multiple columns “order by” criteria
all I’ve been trying to do, with data following the structure: To get the following: Basically, to order the alphabetical field in ascending order, the numerical field in descending order and get the order or rank by using the order used for the numerical field, grouped by the alphabetical field. I have…
Update records in SQL by looking up in different table
I am copying data from few tables in SQL server A to B. I have a set of staging tables in B and need to update some of those staging tables based on updated values in final target table in B. Example: Server B: StagingTable1: StagingTable2: After Copying StagingTable1 to TargetTable1 (ID’s get auto polu…
Consult records within the master detail from the master table Entity Framework Core
I need to consult records within the master detail from the master table. I have the purchases table and the purchases detail table, and I need to consult the purchases that contain the product …
What are the disadvantages when I use mutually dependent foreign keys?
I know that it’s not a good method to use two tables with mutual foreign key definitions, but I don’t understand the difficulties that arise in the database. An example: I’ve a table city and a table state. City.city points at state.capitalcity and state.state points at city.state. I would a…
Get items from next week
I was starting to do a query such as: The problem with this is that items from previous years will also show up here. What would be the best way to do this query — I’m hoping I can still use an index on the query on the date_inserted field, which is why I’m asking this here Answer I would
[21000][1242] Subquery returns more than 1 row
My Query: Here I get the error – [21000][1242] Subquery returns more than 1 row By the method of exceptions, I determined that the error in this query string: How to make the correct request so that there is no this error? Thank! Answer Two common ways are aggregation and limiting: However, those are re…
select max from previous group
I am trying to get the MAX value from the previous group. Here is a sample table. group_id number, cycle number, time number); insert into cycle_times (group_id, cycle, time) values (1, 1, 1); …
Unable to use a select join with this data, when it used to work earlier
Im trying to debug a really weird issue. One of the parts of my database that used to work properly suddenty stopped to work. I have narrowed the problem to this: First of all: Those are my …
SQL query to convert duplicate column values to unique value
Need help to come up with an update query to make the value column to be unique values. I use Postgres. CREATE TABLE test ( id INT, value INT ); INSERT INTO test (id,value) VALUES (‘1′,’100’); …