HomeIntegrationsPricingLearn
Sign inGet started

Data to decisions, faster.

Learn

  • Blog
  • Webinars
  • SQL tutorials

Legal & security

  • Privacy Policy
  • Terms of Use
  • Cookies Policy
  • Trust Center
  • Security

Social

  • LinkedIn →
  • YouTube →
  • X →

Join 4,000+ data professionals who believe data is more than just building chatbots.

A weekly email to help you think through data + AI

© 2026 Count Technologies Ltd. All rights reserved.

Book a Demo →

SQL Resources

Count is the best SQL IDE, wrapped up in the best data analysis tool, all inside the best BI platform.

ARRAY_AGG
Arrays Explained
Arrays Explained
CASE
CAST
COALESCE
CONCAT
COUNT [DISTINCT]
CURRENT_DATE
CURRENT_DATETIME
CURRENT_TIMESTAMP
DATETIME_DIFF
DATETIME_TRUNC
DATE_DIFF
DATE_TRUNC
Data Types
Dates and Times
EXTRACT
IF
DefinitionPractical InfoCommon QuestionsTroubleshooting Common ErrorsRelated Pages
MEDIAN
SUBSTR
String Functions Explained
TIMESTAMP_DIFF
TIMESTAMP_TRUNC
TIME_DIFF
TIME_TRUNC
UNNEST
Window Functions Explained
SQL Resources/BigQuery Standard SQL/IF

IF

IF function. Definition, syntax, examples and common errors using BigQuery Standard SQL. The IF function allows you to evaluate a boolean expression and return different results based on the outcome.

Definition

The BigQuery IF function allows you to evaluate a boolean expression and return different results based on the outcome.

expr must be a boolean expression. If expr is true then the function returns true_result, otherwise else_result is returned.

Practical Info

  • If expr is NULL then the else_result is returned.
  • true_result and else_result can be any data type but must be of the same type.
  • The IF function is similar to the CASE function.

Common Questions

Which is better -  IF or CASE expressions?

For almost all situations you can use IF or CASE interchangeably, but their syntax makes them better suited to different situations.  For simple comparisons IF functions are easier to write, but when there is a list of outcomes the structure of the CASE syntax makes it easier to review.

IF(expr, true_result, else_result)

How can I model situations with more than two possible outcomes?

It is possible to "chain" IF functions together to provide results for a number of different logical outcomes by replacing true_result and else_result with a followup IF function. For example:

SELECT
  fruit,
  IF((fruit = 'apple'), 'It is an apple', 'It is a pear') AS apple_or_pear
FROM
  (
    SELECT
      'apple' AS fruit
    UNION ALL
(    SELECT
      'apple' AS fruit)
    UNION ALL
(    SELECT
      'pear' AS fruit)
  ) AS table_3
fruitapple_or_pear
appleIt is an apple
bananaIt is a banana
pearIt is a pear

Troubleshooting Common Errors

Could not cast literal to type DATE

SELECT
  fruit,
  IF((fruit = 'apple'), 'It is an apple', IF((FRUIT.fruit = 'banana'), 'It is a banana', 'It is a pear')) AS apple_or_pear
FROM
  (
    SELECT
      'apple' AS fruit
    UNION ALL
(    SELECT
      'banana')
    UNION ALL
(    SELECT
      'pear')
  ) AS FRUIT

This error occurs when the two different results true_result and else_result are of different data types, specifically in this example one of the results is a date and the other is a data type which cannot be converted to a date. If you get this, check your logic and column types or consider using the CAST function.

No matching signature for function IF for argument types... Supported signature: IF(BOOL, ANY, ANY).

This error occurs when the expr does not evaluate to TRUE or FALSE (ie expr is not a boolean expression).

Related Pages

Got a CSV?
See it differently in <2 mins

Get started for FREEWatch our CEO do it