I have a somewhat methodical method for constructing queries in general, and this is what I use elsewhere with any solution to the problem that I need to make.
At the first stage, ALWAYS lists any bits of information that I have in the request. Information is, in fact, something that tells me something.
The table contains one column having a duplicate record. I need to remove duplicate
- I have a table (I will call it table1)
- I have a table column table1 (I will call it col1)
- I have duplicates in col1 in table table1
- I need to remove duplicates.
The next step in my query design is to identify the action that I will take from the information . I will search for specific keywords (for example, delete, create, edit, show, etc.) Together with the standard insert, update, delete to determine the action. In the example, this will be DELETE due to deletion.
The next step is isolation .
In response to the question "should the action above be valid only for ______ ..?" This part is almost always the most difficult part of constructing any query, since it is usually abstract. In the above example, you specify “duplicate entries” as part of the information, but this is really an abstract concept of something (something where a particular value is not unique to use). Isolation is also where I test my action with the SELECT statement. Every new request that I run is triggered with a first choice!
The next step will be to execute, or essentially a part of the “how to do it” request.
Many times you define how at the isolation stage, but in some cases (including yours), how you isolate something and how you correct it is not the same thing. Displaying duplicate values ​​is different from deleting a specific duplicate.
The final step is implementation . This is exactly where I take everything and make a request ...
To summarize ... for me, to build a query, I will select all the information that I have in the query. Using the information, I will find out what I need to do (action ), and what I need to do ( isolate ). As soon as I find out what I need to do with the fact that I figured out the execution .
Each time I start a new “query”, I start it using these general steps to get an idea of ​​what I'm going to do at an abstract level. For specific implementations of the actual request, you will need to have some knowledge (or google access) to go beyond this.
Kris