Skip to content

Tag: sql

Auto-increment a primary key in MySql

During the creation of tables using mysql on phpmyadmin, I always find an issue when it comes to primary keys and their auto-increments. When I insert lines into my table. The auto_increment works perfectly adding a value of 1 to each primary key on each new line. But when I delete a line for example a line w…

JOIN ON either of the two columns but not both

I have two tables (orders, agents) i’m trying to join on either of the two columns but not both. There are some records in orders that have both of these columns populated and it returns as duplicate orders: agents: I tried joining with an OR clause I’m getting the following results Expected Resul…

SQL- Find the price of the smallest product in a store

I would like to find the price of the smallest product in a store and in addition, in another column, populate this price in all the products of the same store. Here is my table and the desired result in the “results” column: Table1 Here is my request but it does not populate the price: SELECT loc…

subtraction of 2 select statements

I have a simple table: Neighbourhood Some countries have the same neighborhood name. All I want is the total minus the distinct. but I have a problem with the operator; Here is what I am doing. Answer So you want: I might suggest a further breakdown: This shows the frequency of duplication along with example …

SQL multi save without using loop/ cursor

I have a requirement where from a string of int[] I need to insert all the values of this array into DB. I have tried this solution and it works fine. To achieve this I have converted the int[] to XML in C#, and in SP used this XML variable to fill a table variable and looped over this table