Sql check if record exists in another table

Today, We want to share with you sql if exists else.In this post we will show you sql if exists drop table, hear for sql query to check if value exists in column we will give you demo and example for implement.In this post, we will learn about JQuery Check If Element Exists Or Not with an example.

If Exists then Update else Insert in SQL Server

here learn to IF Exists …Else If Exists…In SQL Examples

Read Also:  PHP mysqli_num_fields - Function MySQLi Num Fields

Example 1: sql server if exists update else insert

if exists(SELECT * from Employee where UserNm='Virat' and ProfileNm='Kartani')            
BEGIN            
 update mployee set UserNm='Anu' where UserNm='Virat'  
End                    
else            
begin  
insert into mployee values(1,'Virat','Kartani',28,'Male',2006,'Noida','Tenth','LFS','Delhi')  
end 

Example 2:

SELECT SupplierName
FROM AllWorkers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = AllWorkers.supplierID AND Price < 20);

Example 3:

SELECT SupplierName
FROM AllWorkers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = AllWorkers.supplierID AND Price = 22);

IF EXISTS (SELECT * FROM tblGLUserAccess WHERE GLUserName ='jaykishansharma') 
BEGIN
   SELECT 1 
END
ELSE
BEGIN
    SELECT 2
END

I hope you get an idea about sql check if record exists in another table.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  How to get all products in WooCommerce

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *