Questions tagged [where-clause]
A syntactic form in functional languages used to bind a value to a name in a local scope. Similar, but not identical to, let.
9,100
questions
0
votes
0
answers
42
views
How to filter data with two different situations using case statements in SQL [closed]
I have a database with fields and structures that is mentioned below:
id BIGINT UNSIGNED PRIMARY KEY
name VARCHAR(255) #Game ID
platform VARCHAR(255) #The name of the game
year_of_release YEAR #Year ...
0
votes
2
answers
43
views
Is there a way to combine these two MySQL queries into a single statement?
I'm trying to do some dynamic variable calculations on a select and reference those variables in the where statement. After searching the following is as close as I've been able to get thanks to Jonas'...
0
votes
0
answers
35
views
Aggregation does not work properly in sql, in a many to many relationship, because of where clause
My setup
I have two tables, watch, and tags. They are in a many to many relationship joined by a table called linked_watch_tags. I have a query, where I JOIN these tables, GROUP the query by the watch....
-1
votes
1
answer
52
views
Work out in SQL the total money made from increments
I want to work out money made by our automated system
say
Product
Margin
Previous Margin
Type
Purchases
Oranges
1
0
Manual
3
Oranges
2
1
Auto
4
Oranges
3
2
Auto
6
Oranges
4
3
Auto
3
Oranges
1
4
...
0
votes
0
answers
18
views
Using Wildcard in FLWOR
I´m trying to use wildcards in a where clause to recieve elements from an xml file. I´m using BaseX and the built in editor.
This line of code:
for $route in //route
where $route/string(@routeinfo) ...
-1
votes
0
answers
74
views
Why are the results different filtering with SQL WHERE clause: NOT with OR vs NOT IN [closed]
I want to filter out the rows that contain 'test', 'TEST' or 'Test'.
Around 6,000 rows match this condition. Therefore, the number of rows my query should return is the total number of rows minus 6,...
0
votes
0
answers
8
views
No matching signature for operator > for argument types: FLOAT64,
I have the follow syntax
select vendornumber,
Round(Sum(Freight),2) As Freight
From VendorInv
Where Dollars > '100'
AND Quantity <= '1000'
Group By VendorNumber
Order By Freight DESC
but i'm ...
0
votes
1
answer
51
views
Exclude rows that contain partial data
I have a field in my dataset that has rows that need to excluded from my output that have the word "invalid" in the field. The data is as follows:
100 - 100 - 100
100 - invalid - 300
200 - ...
-4
votes
2
answers
65
views
SQL WHERE clause matching on the same field twice (or more). What is the right JOIN statement to be used? [duplicate]
I have a DB with two tables:
employees table: fields = {ID, name}
turnShift table: fields = {ID, date, ID_employee1, ID_employee2}
Here is an example of this DB.
Using MYSQL, I'd like to execute a ...
-2
votes
1
answer
29
views
What are the main differences between HAVING and WHERE SQL clauses? [duplicate]
the main differences between HAVING and WHERE SQL clauses in sqlserver ,for example ,How would you write a query to identify employees belonging to a particular department by using two ways sepetately,...
2
votes
2
answers
92
views
Calculating Age without using a function in the where clause
I have been reading about avoiding using functions in the WHERE clause (as they often have to use scans and are generally not very efficient).
I have an SP that calculates a customers age based on ...
0
votes
1
answer
31
views
Returning a filtered list of items from where the ID is in a list from another array of matching guids
After a bit of help to get the a list filtered using another list of items. Ordinarily I'd of coded around this in SQL, but I need to try to get this working in .NET.
I have a list of Roles, and each ...
0
votes
2
answers
25
views
Why is SQL query only returning records for a single item in 'WHERE' 'IN' clause?
Why does this query:
SELECT
dr.facility_id,
ds.sys_sample_code,
ds.sys_loc_code,
ds.matrix_code,
ds.sample_type_code,
ds.start_depth,
ds....
0
votes
1
answer
30
views
How to generalize a "WHERE" clause in a SQL trigger
I'm very new to SQL and practicing creating trigger functions right now. Currently I'm trying to create a stored procedure to update product records when a sale or stock update occurs. Right now, it ...
0
votes
0
answers
18
views
Joining two tables and only listing by specific value in shared field
Trying to use INNER JOIN to combine two table in a class simulation. Once I've listed the fields I need to narrow the return to just items listed as category 3. Tried this
SELECT CategoryName, ...
0
votes
1
answer
31
views
SQL Assistant with Where Clause
I am using SQLite. Below is my code and Excel screenshot of some of the columns I am using from SQLite. I am trying to create a where clause that will select the times in the registered at column that ...
0
votes
2
answers
60
views
Why the result is different for SQL string equality and for LIKE operator in Postresql? [closed]
I have a table with login names. Login names does not contain any special character just [a-zA-Z0-9] and of type varchar(50).
I would like to find a user by login name eg.:
CREATE TABLE users( login ...
-1
votes
1
answer
65
views
Why can't I use "group by" instead of a "where"clause? #Mysql #sql
Mysql doesn't execute the group-by version. I am trying to understand why this happens, because as far as I understand, 'group by' syntax is used after aggregation, BUT why here it doesn't work?
The ...
0
votes
1
answer
52
views
Date CAST in WHERE clause does not return items
I have a problem with SQL query that has a CAST function in it, so this is my condition:
CASE
WHEN FYStartMonths = 1
THEN
'Period ' + CAST((MONTH(EndDate) + 1) / 2 AS VARCHAR) + ' ' + CAST(...
-1
votes
1
answer
2k
views
AS400 DB2 Does not support JOIN with = 'xxxxxxxxx'?
Im trying to do a inner join and add a where clause on it.
The where clause is a number given by API call and retrive the lettres written by a person.
When i add a MATCHING where clause its not ...
0
votes
1
answer
123
views
MySQL Query Slowing Down on introduction of Where Clause
I am writing a MySQL procedure that calculates proxy costs for inventory items added in physical inventory audits. I have created a cost map that contains date and product wise proxy costs and another ...
0
votes
1
answer
59
views
Snowflake flatten json SQL
I have a list of a lot of product IDs saved in a .csv file.
I need to query Snowflake for the product IDs, where each product ID is couched inside a JSON object in a field called PRODUCTCODES. Each ...
0
votes
3
answers
87
views
c# lambda expression with specific "where" "is null"
Could somebody tell me how to create a c# lambda expression to get the following result:
I want to get all rows with value NOT starting with a 'B'. So rows with ID 1,3,4,5 and 6 need to be in the ...
1
vote
1
answer
45
views
Merging (adding) pandas column data using column name based on other columns contents (opposite direction values)
I have a pandas dataframe that contains link information based on nodes and links ending at particular node.
To this information I would like to add information about links in opposite direction.
...
0
votes
1
answer
49
views
CakePHP 4 query: where clause with nested table not working?
I'm working for my first time with CakePHP and I'm trying to do a (really simple) query but I'm not managing to get it done. I have set up all the tables of my database, and that is working well. Now, ...
-1
votes
1
answer
127
views
GETDATE month in where clause
I have this table:
Key_No
Import_Date
12345678
2023-09-01
98765432
2023-10-01
85231654
2023-11-01
00020102
2023-12-01
I want to find the data of import_date after this month.
I tried a SQL ...
0
votes
1
answer
62
views
In Adf I want to make a column 'test' that has a different value for every month value in the 'date' column
I have a column full with dates. Now I want to make a second column 'test' that is based on this column. Whenever the month changes in the 'date' column I want the number in the 'test' column to be ...
0
votes
0
answers
35
views
PySpark filter works incorrectly with one True built using lambda funtion
I was debugging a function and I have encountered a misterious thing:
Given a PySpark dataframe with one column (name_id) I build another (is_number) one using a lambda function to see if name_id is a ...
1
vote
2
answers
48
views
MySQL: Have unique values in a column with one exception [duplicate]
I've created a column of usernames but the ids for each row is linked to another table. If a user is deleted, I'd like to change the username to 'Deleted'. So I'd like to allow for unique values ...
0
votes
0
answers
30
views
mysql procedure parameter text to using where condition
i correr it by have error on column name by alias table name
ERROR MESSAGE
Type: mysqli_sql_exception
Message: Unknown column 'created_at' in 'field list'
call projects_view(20,0, "(p.created_at &...
1
vote
1
answer
24
views
MS Access Messenger App with user filtering of messages
I am in the making of an internal short message app in our MS Access "ERP system".
The table is called "tbl_0_messages"
Field Name DataType Lookup
message_id ...
2
votes
2
answers
88
views
How to write a WHERE clause with row_number in T-SQL?
WITH CTE AS
(
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY opened_at) RN
FROM
table
)
SELECT column1, column2
FROM CTE
WHERE RN = 2
If there is no RN = 2, ...
0
votes
1
answer
24
views
Knex whereExists query with jsonb_array_elements
I have query on postgres like this and that working well
SELECT *
FROM table_name
WHERE NOT EXISTS (
SELECT 1
FROM jsonb_array_elements(column1) AS elem
WHERE elem::jsonb ? 'answer'
) AND ...
0
votes
2
answers
51
views
Oracle SQL where clause evaluating two columns
I have basic SQL skills but I'm stumped by this:
create table scores
(
name varchar2(15),
history_grade varchar2(1),
math_grade varchar2(1)
);
insert into scores (name, history_grade, ...
0
votes
0
answers
14
views
MySQL Multiple Where Clauses from multiple tables
I would like to select data from two tables. The 2nd table has multiple entries with a relationship to the 1st.
1st Table - Part
Part_id
Repair no.
Report no.
1
null
null
2
null
1234
3
null
null
...
0
votes
0
answers
29
views
Is a Join clause somehow special? [duplicate]
When joining tables there are two ways, that are logically the same:
Select *
From tab1, tab2
Where tab1.ID = tab2.ID
Select *
From tab1
Join tab2 On tab1.ID = tab2.ID
You hear about join would ...
-1
votes
1
answer
33
views
SELECT rows from my table where the start and end times are within my shift ranges
SELECT
[Machine_Events_ID],
[Event_TimeStamp],
[Event_EndTimeStamp],
[Bucket_ID],
[PartNumber]
FROM
[A5].[dbo].[Machine_Events]
WHERE
DATEPART(hour, Event_TimeStamp) >...
-1
votes
1
answer
50
views
Google sheet query where clause only return in one row
I usually use this formula but I do not know why this time it only show in one row. this formula just to call return to the other sheet.
Here is the formula :
=QUERY(IMPORTRANGE("...
0
votes
1
answer
39
views
SQL group by multiple columns with seperate where statements and left join
I want to select all delivery stops for a driver. If 2 orders have the same delivery_id location it should only be one stop. Similarly if the pickup_id and delivery_id of different orders are the same ...
0
votes
0
answers
40
views
undefined method `ids' for [#<User id:..] - rails graphql API - why i should add users.to_a in my code
def resolve(where: {}, order_by: {'field': 'updated_at', 'direction': 'desc'})
order_by.symbolize_keys!
[context[:current_user]] unless context[:current_user].has_capability?(self.class.name....
0
votes
2
answers
83
views
SQL Snowflake: Value does not show up in SELECT * search but does show up when included in WHERE Clause
Hello and thank you in advance!
I have a SQL query that returns a list of customers for a course ID where the status is 'active'. I noticed the total count was incorrect and that there were a few ...
0
votes
4
answers
77
views
Distinct without group by/having/distinct [duplicate]
I am trying to find an appropriate solution to the following problem:
I have an activity-tracking database and I want to get the status at a specific date (ex: 11-Sept)
Activity
Status
Date
100
Done
...
0
votes
1
answer
64
views
EF Core 7 with multiple dynamics where conditions
Good morning everyone, first of all sorry for my bad English. I use EF Core 7 and I need to filter the data of a SQL database by setting a sequence of conditions whose number I don't know a priori.
...
0
votes
1
answer
37
views
Define const generics in the where clause
Is there any way to define a const generic in the where clause, currently it doesn't seem to work. If there isn't, are there any plans of adding it in the future?
My Failed Attempts
fn foo<N>()
...
0
votes
2
answers
145
views
Snowflake uses where-clause in wrong place when joining
I have views that I need to join, and these have filters to exclude records with invalid data. In the views the filtering is done before the remaing records are cast to their respecive data type, but ...
0
votes
0
answers
6
views
Can we use select statement with count in triggers on view table
I am trying to write like this... but it showing error
Error Code: 1415. Not allowed to return a result set from a trigger
delimiter //
CREATE TRIGGER ins_transaction5 BEFORE update ON prd
for each ...
-3
votes
2
answers
67
views
SELECT Statement with "IF" included in WHERE?
I have a query that's pulling in data for all Product Serial Numbers above that are in Workflow "A". However, in some cases there are serial numbers in both Workflow A and B.
When this ...
0
votes
0
answers
43
views
Is there a reason for SQLite allowing me to filter a created column and PostgreSQL not
I was wondering why is it that I could filter a created column in the WHERE clause when I thought that due to Order of execution It was not allowed. In SQLite I was able to filter a column that I ...
-1
votes
2
answers
47
views
Use a column of arrays as a condition in Postgresql
I want to use a column of arrays as a condition in postgres. The condition is applied on a column composed of text value.
This is the column made out of arrays (after be transformed with ...
-2
votes
2
answers
49
views
SQL query to exclude rows from the main query based on a sub-query that checks ALL rows exist
I have a query that returns data from a main table (Works) and pulls in some addition data (Publishers) using a sub-query in the SELECT list, that is then grouped up into a CSV list. Something like ...