cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

What is the equivalent of "if exists()" in databricks sql?

reachrishav
New Contributor II

What is the equivalent of the below sql server syntax in databricks sql? there are cases where i need to execute a block of sql code on certain conditions. I know this can be achieved with spark.sql, but the problem with spark.sql()  is it does not provide the number of affected columns (insert/update/delete) after the execution of dml statement.

IF EXISTS(SELECT 1 FROM table WHERE col = value)

BEGIN

     DELETE FROM table WHERE col = value

END

ELSE

BEGIN

    <code to run in else>

END

 

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group