w3resource

AdventureWorks Database: Check for similarity of the values

SQL Query - AdventureWorks: Exercise-131 with Solution

131 From the following table write a query in SQL to check the values of MakeFlag and FinishedGoodsFlag columns and return whether they are same or not. Return ProductID, MakeFlag, FinishedGoodsFlag, and the column that are null or not null.

Sample table: production.Product


Click to view Full table

Sample Solution:

SELECT ProductID, MakeFlag, FinishedGoodsFlag,   
   NULLIF(MakeFlag,FinishedGoodsFlag) AS "Null if Equal"
FROM Production.Product  
WHERE ProductID < 10;

Sample Output:

productid|makeflag|finishedgoodsflag|Null if Equal|
---------+--------+-----------------+-------------+
        1|false   |false            |             |
        2|false   |false            |             |
        3|true    |false            |true         |
        4|false   |false            |             |

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Select data from first column that has a nonnull value.
Next: Return any distinct values that are returned by both the queries.


What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

Convert Timestamp to date in MySQL Query:

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'

Database: MySQL

Ref : https://bit.ly/3EJPnMQ