WHERE clause condition when a column has a specific value

Related searches

I'm facing a problem in WHERE clause in my query:

SELECT
p.productId,
p.productType,
p.quantity_for_customers,
p.quantity_for_sellers,

FROM dbb.Products


WHERE (p.productType IS NOT NULL 
      OR 
      (p.productType = 1 AND p.quantity_for_customers > 0 
          AND p.quantity_for_sellers > 0)
      )

I want to select product information, but if the product has type = 1, then I want to select that product if both quantities (customers and sellers) are greater than zero.

The WHERE clause I wrote does not work because some products have type = 1, but one for their quantites is = 0, but they still show up in query results.

What's wrong with the WHERE clause?


WHERE p.productType <> 1
   OR (p.productType = 1 AND p.quantity_for_customers > 0 AND p.quantity_for_sellers > 0)

How to Filter Query Results using WHERE, A simple example of a Select statement with a where clause is Select CustomerName An equality condition tests that a column or expression matches a value. You may have noticed that numbers are written as is, however, the text is enclosed in single quotes. In your specific situation you are not retrieving duplicates. This example retrieves records that are no older than 1 hour, come from a source called MyCluster, and have two columns of the same value. Notice that we put the comparison between two columns last, as it can't use the index and forces a scan. Example Traces | where * has "Kusto" All the rows in which the word "Kusto" appears in any column.


They show up, because the procutType is not null. Combined with the OR every entry whill show up that statisfies the condition productType IS NOT NULL.

To achieve what you want try this:

WHERE p.productType IS NOT NULL AND
  (p.productType <> 1
  OR 
  (p.productType = 1 AND p.quantity_for_customers > 0 
      AND p.quantity_for_sellers > 0)
  )

SQL WHERE: Filter Rows Based on a Specified Condition, To select certain rows from a table, you use a WHERE clause in the SELECT Note that SQL has three-valued logic which is TRUE, FALSE, and UNKNOWN. be either column name on one side and a literal value on the other, for example:. for ex, I have value "TC001" repeated for 4 times in columnA and the corresponding values in Column B will be as shown below Column A Column B TC001 BASE_1106ST TC001 BASE_1106ST TC001 BASE_1102IMT TC001 BASE_1108ST I need a formula to find the max value in column B. The max value in column B in this example is "BASE_1108ST" Could anyone please


SQLite WHERE - Filter Rows in a Result Set, In this example, you add a WHERE clause to the SELECT statement to filter rows returned The search condition in the WHERE has the following form: SQLite compares the values stored in the AlbumId column with a literal value 1 to test if� Drop rows from the dataframe based on certain condition applied on a column Pandas provides a rich collection of functions to perform data analysis in Python. While performing data analysis, quite often we require to filter the data to remove unnecessary rows or columns.


Your condition can be simplified to this:

WHERE p.productType <> 1
      OR 
      (p.productType is not null and p.quantity_for_customers > 0 AND p.quantity_for_sellers > 0)

See a simplified demo.

SQL WHERE Clause, The WHERE clause is used to extract only those records that fulfill a specified condition. Note: The WHERE clause is not only used in SELECT statement, it is also used in Select all records where the City column has the value "Berlin". One way to filter by rows in Pandas is to use boolean expression. We first create a boolean variable by taking the column of interest and checking if its value equals to the specific value that we want to select/keep. For example, let us filter the dataframe or subset the dataframe based on year’s value 2002. This conditional results in a boolean variable that has True when the value of year equals 2002, False otherwise.


Using the SQL WHERE clause, The WHERE clause compares the value in a specified column against a clause to return everything the condition following the NOT have not specified. How do i filter a where condition based on the parameter value,for example i have the following parameter that can be a "History" or "latest" as such Declare @Type nvarchar(10) set @Type='History' so now i want to say in my where clause if type = history than do the first query if its equal to latest than do the second query


AND fname = original-value AND lname = original value AND status = original value; Here the UPDATE statement is checking all updatable columns in the WHERE clause. This statement will fail if any of the updatable columns for employee 1001 have been changed since your application retrieved the row.


Filter Rows based on Value/Condition and Then Delete it. One of the fastest ways to delete rows that contain a specific value or fulfill a given condition is to filter these. Once you have the filtered data, you can delete all these rows (while the remaining rows remain intact).