Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in SQL by (6.1k points)
How can I check whether there already is any duplicate entry in the available database? I don't want to prevent it, simply a warning. Thus if it already exists it just gives a warning, and it's up to the user to ignore it or not.

1 Answer

0 votes
by (12.7k points)
edited by

You can use the following code:

$key_id = 123;

$result = mysql_query("SELECT * FROM table WHERE key_id='$key_id'");
$num_rows = mysql_num_rows($result);

if ($num_rows) {
   trigger_error('It exists.', E_USER_WARNING);
}

Want to learn more concepts related to SQL? Join this SQL Course by Intellipaat.

Related questions

0 votes
1 answer
asked Dec 31, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 19, 2020 in SQL by Appu (6.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...