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.

9069 questions
28
votes
8 answers

SQL Server: How to use UNION with two queries that BOTH have a WHERE clause?

Given: Two queries that require filtering: select top 2 t1.ID, t1.ReceivedDate from Table t1 where t1.Type = 'TYPE_1' order by t1.ReceivedDate desc And: select top 2 t2.ID from Table t2 where t2.Type = 'TYPE_2' order by t2.ReceivedDate…
aarona
  • 35,986
  • 41
  • 138
  • 186
28
votes
5 answers

Finding entries containing a substring in a numpy array?

I tried to find entries in an Array containing a substring with np.where and an in condition: import numpy as np foo = "aa" bar = np.array(["aaa", "aab", "aca"]) np.where(foo in bar) this only returns an empty Array. Why is that so? And is there…
SiOx
  • 478
  • 1
  • 6
  • 13
28
votes
6 answers

CodeIgniter: How to use WHERE clause and OR clause

I am using the following code to select from a MySQL database with a Code Igniter webapp: $query = $this->db->get_where('mytable',array('id'=>10)); This works great! But I want to write the following MySQL statement using the CI library? SELECT *…
tarnfeld
  • 25,992
  • 41
  • 111
  • 146
28
votes
2 answers

MySQL: how to index an "OR" clause

I'm executing the following query SELECT COUNT(*) FROM table WHERE field1='value' AND (field2 >= 1000 OR field3 >= 2000) There is one index over field1 and another composited over field2&field3. I see MySQL always selects the field1 index and then…
JoséMi
  • 11,642
  • 2
  • 21
  • 25
28
votes
5 answers

How do I create a conditional WHERE clause?

I need to have a conditional where clause that operates as so: Select * From Table If (@booleanResult) Begin Where Column1 = 'value1' End Else Begin Where column1 = 'value1' and column2 = 'value2' End Any help would be appreciated.
Yatrix
  • 13,361
  • 16
  • 48
  • 78
27
votes
1 answer

Swift protocol with "where Self" clause

In addition to this syntax with a protocol extension: protocol P {} extension P where Self : UIView {} ... I discovered by accident that you can use the same where clause on the protocol itself: protocol P where Self : UIView {} Notice that this…
matt
  • 515,959
  • 87
  • 875
  • 1,141
27
votes
3 answers

LINQ Join Where Clause

I'm struggling with a join/where clause with what is a rather simple sql select statement. I am trying to retrieve a list of product information from tb1 with the where condition behind situated in tbl2 but this must be joined by three different…
Ricardo Deano
  • 2,769
  • 8
  • 47
  • 70
27
votes
2 answers

SQL use column from subselect in where clause

I have a query that looks something like that: SELECT a, b, c, (SELECT d from B limit 0,1) as d FROM A WHERE d >= 10 I get the result that I want when I run the query without the whereclause but when I add the where clause the query fails. Does…
Chris
  • 3,057
  • 5
  • 37
  • 63
27
votes
3 answers

SQL User Defined Function Generates a Non-Boolean Type Error

I'm getting this error on a SQL user defined function: An expression of non-boolean type specified in a context where a condition is expected, near ')'. For this: UPDATE LMI_Contact SET Phone = NULL WHERE dbo.LMI_IsSingleCharacterRepeated(Phone,…
Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
27
votes
3 answers

Haskell where clause syntax inside a do block

I am trying to refactor a mapM_ function call inside a do block in Haskell. I would like to extract the lambda to a (locally) named function to make the code more readable. My code originally looks like this: do -- ... mapM_ (\x -> x + 1)…
Ralph
  • 31,584
  • 38
  • 145
  • 282
26
votes
1 answer

Is multiple .Where() statements in LINQ a performance issue?

I am wondering if there are performance implications of multiple .Where() statements. For example I could write: var contracts = Context.Contract .Where( c1 => c1.EmployeeId == employeeId ) .Where( c1 => …
John
  • 2,043
  • 5
  • 28
  • 49
26
votes
2 answers

Postgres excludes NULL in WHERE id != int query

I came up against a strange problem in Postgres yesterday when trying to filter out user ids from a stats table. When we did, for example, user_id != 24, postgres excluded the rows where user_id is NULL as well. I created the following test code…
mouckatron
  • 1,289
  • 2
  • 13
  • 23
26
votes
3 answers

Update substring of a column

I have a table within a SQL Server 2008 database called Meter. This table has a column called Name. Each entry within the column Name has a prefix of the following ZAA\. I'd like to change this prefix to ZAA_ without affecting the rest of the text…
user2547340
  • 325
  • 3
  • 6
  • 13
26
votes
2 answers

Conditional WHERE clause with CASE statement in Oracle

I'm brand-new to the Oracle world so this could be a softball. In working with an SSRS report, I'm passing in a string of states to a view. The twist is that the users could also pick a selection from the state list called "[ No Selection ]" ...…
Rob Horton
  • 785
  • 3
  • 9
  • 27
26
votes
3 answers

PHP MySQL Query Where x = $variable

I have this code (I know that the email is defined)
user2224376
  • 397
  • 1
  • 3
  • 5