In this article, we will find out going to discover copy records in database utilizing SQL Query and afterward make 2 to 3 inquiry to take out the copy record and resolve the issue.
A Table in a social database can have numerous fields for example id, name and address. Presently, there are situations when we need to have at least one fields which can be copied.
This can be comprehended as the name of individual or address of two people having same or diverse name in the table. Presently, finding these records can be somewhat dubious as we don’t have any key which can be worked for all the records in the table.
SQL language gives certain functions which ought to be utilized while doing these sorts of tasks. One of them is check, which is utilized to tally the quantity of records which are chosen by the inquiry.
Having said that, one issue emerges that how might we use tally to separate among copy and one of a kind records. Well the appropriate response is extremely straightforward, we should simply to amass them by there comparing fields which are inclined to be copied.
Presently at long last we will have number of records which are masterminded with their comparing field or fields. At that point, the exact opposite thing we need to do is to sift through the records which have there counter littler or equivalent to zero.
At long last, we will be left with the record whose field will be copied.
Table (employee) having three fields and four data in it:
Id Name Address 100 Aman Mumbai 200 Arun Pune 300 Karan Delhi 400 Aman Mumbai
Here, in above table we have a copy section of name “Aman” where the email is likewise same, presently we have to make a question to locate the copy field in database.
Query 1:
SELECT name, email, COUNT(name)
FROM employee
GROUP BY name, email
HAVING COUNT(name)>1;
Output:
Query 2:
SELECT name, COUNT(name)
FROM employee
GROUP BY name, address
HAVING COUNT(name)>1;
Output:
Query 3:
SELECT address, COUNT(address)
FROM employee
GROUP BY name, address
HAVING COUNT(address)>1;
Output: