Skip to content
Advertisement

Filtering/ORDER BY – Practice

I ran into a small issue with a order I am trying to do and not sure if there is a solution to what I am trying to accomplish. I have the following table created… CustomerID is PK and I can’t change the numbers around.

The goal is to get the table to look like this:

The first part of what I’m trying to accomplish is adding the following record/row/entry (seen here)

I was successfully able to add the row using INSERT INTO. The next task I wanted to accomplish was sorting (ORDER BY) the table by ProductID AND State. As you can see I am trying to move that new row to the new position as seen above.

As of now I have tried:

My table looks like this

This changes the order of customer ID 5,6,7 which I am trying to avoid.

I tried to create a CASE but had no luck and wasn’t able to “double sort” (error because my first 2 columns are int and can’t compare to my 3rd column)

Any recommendations? Advice? Is what I’m trying to accomplish even possible?

Advertisement

Answer

Probably this is what you are after?

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement