Skip to content
Advertisement

Tag: where-clause

SQL where clause selecting specific data

In Microsoft SQL, I am trying to select a specific result from a table when available. Otherwise, other data should be retrieved. Giving the scenario tableA contains various fruits. I want to collect apples that are red otherwise, any other colors except for red should be retrieved. I am not sure which approach to go with, having a Case Statement

Using a subquery in a case statement in a where clause

I want to select different results (from a temp table) based on what a certain parameter is set to in the query. I want to exclude certain inventory SKUs if a particular warehouse is selected. I am getting this error, unfortunately. Msg 512, Level 16, State 1, Line 310 Subquery returned more than 1 value. This is not permitted when

SQL return rows on or after an specific date

I am trying to export a list of member details that have an expiry date after 2019 so I am just after I thought I could simply use the date in a WHERE clause However, it still returns the other entries and not sure why Answer Assuming that you are using SQL Server: dbfiddle

Use one of two dates in where clause

I need to delete all records in a table where the CreatedDate or ModifiedDate is greater than x. The logic is as follows: If ModifiedDate is not null then use this value Otherwise use the CreatedDate value Not applying the if/else statement correctly. Answer Use this where clause:

SQL CASE that matches value or uses LIKE ‘%’

I’m trying to do a wildcard retrieve if a defined variable is blank. But I can’t figure out the correct syntax. Answer It is as simple as this: The expression NULLIF(x, ”) will convert ” to null. Then we take advantage of how null comparison works: If @customerID is not null then first condition will be true only for exact

Why doesn’t the WHERE work in this sql query

I’m writing a SQL query that needs to only show the results where the ‘titel’ is the same as ‘Baklava’, but it doesn’t return any rows. When I try to use the query without the WHERE, is shows all the results, but I need the WHERE clause to work. Here is the query I’m trying to use: import.sql: Answer You

SQL Insert into with join and where

I have three tables. For example: newTable: oldTable: associativeTable: What I want to do now is: I want to move the name column from oldTable to newTable. I have already altered newTable and added an empty name column. Now I’m trying to write a correct INSERT INTO statement. What I have so far is: I’m a bit lost on it.

MySQL table update after multi field check

Hi I have two table one like this one: table1 and one like this: table2 I would like to update all the fields on the table2 column “newID” based on this rules: if (table2.ID = table1.ID_actual or table2.ID=table1.ID_old) then table2.newID = table1.newID How can I resolve this problem ? Answer You need a join of the 2 tables in the

Advertisement