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

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.

Leave a Comment