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
36
votes
2 answers

Sequelize - subquery in where clause

I'm using Sequelize in my Express app. I need to generate a query that has a subquery in the WHERE clause. SELECT * FROM MyTable WHERE id NOT IN ( SELECT fkey FROM MyOtherTable WHERE field1 = 1 AND field2 = 2 …
hungerstar
  • 21,206
  • 6
  • 50
  • 59
36
votes
3 answers

Difference between filtering queries in JOIN and WHERE?

In SQL I am trying to filter results based on an ID and wondering if there is any logical difference between SELECT value FROM table1 JOIN table2 ON table1.id = table2.id WHERE table1.id = 1 and SELECT value FROM table1 JOIN table2 ON…
warsong
  • 1,008
  • 2
  • 12
  • 21
35
votes
4 answers

T-SQL Conditional WHERE Clause

Found a couple of similar questions here on this, but couldn't figure out how to apply to my scenario. My function has a parameter called @IncludeBelow. Values are 0 or 1 (BIT). I have this query: SELECT p.* FROM Locations l INNER JOIN Posts p on…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
35
votes
9 answers

If condition in LINQ Where clause

With Linq, can I use a conditional statement inside of a Where extension method?
34
votes
5 answers

SQLSTATE[42S22]: Column not found: 1054 Unknown column - Laravel

I'm using the framework Laravel. I have 2 tables (Users and Members). When I want to login, I get the error message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_email' in 'where clause' (SQL: select * from members where…
Gilko
  • 2,280
  • 8
  • 36
  • 45
34
votes
3 answers

LINQ Where with AND OR condition

So I have managed to get this query working List listStatus = new List() ; listStatus.add("Text1"); List listMerchants = new List() ; listMerchants.add("Text2"); from item in db.vw_Dropship_OrderItems …
Zeus
  • 3,091
  • 6
  • 47
  • 60
33
votes
3 answers

UPDATE Query without WHERE Clause

Can the UPDATE query be used without a WHERE clause? And if so in what conditions?
heretolearn
  • 6,387
  • 4
  • 30
  • 53
32
votes
9 answers

SQL Filter criteria in join criteria or where clause which is more efficient

I have a relatively simple query joining two tables. The "Where" criteria can be expressed either in the join criteria or as a where clause. I'm wondering which is more efficient. Query is to find max sales for a salesman from the beginning of…
Gratzy
  • 9,164
  • 4
  • 30
  • 45
30
votes
6 answers

MySQL Multiple Where Clause

I have a table like this: id image_id style_id style_value ----------------------------------- 1 45 24 red 1 45 25 big 1 47 26 small 1 45 27 round 1 49 28 rect I…
Bugra YUKSEL
  • 379
  • 1
  • 3
  • 7
30
votes
6 answers

Difference between "on .. and" and "on .. where" in SQL Left Join?

Sql statement. 1.select a.* from A a left join B b on a.id =b.id and a.id=2; 2.select a.* from A a left join B b on a.id =b.id where a.id=2; what is the difference of this two sql statement?
jack.li
  • 973
  • 1
  • 9
  • 20
30
votes
8 answers

MySQL WHERE IN

Is there a way (without JOIN) to use the WHERE clause on 2 columns (OR) IN a subquery? Currently, I'm doing WHERE 'col1' IN ( SELECT id FROM table ) OR 'col2' IN ( SELECT id FROM table ) And I'm sure I can do better :) . i've also tried…
Max13
  • 919
  • 2
  • 9
  • 27
29
votes
6 answers

What's the difference between "where" clause and "on" clause when table left join?

SQL1: select t1.f1,t2.f2 from t1 left join t2 on t1.f1 = t2.f2 and t1.f2=1 and t1.f3=0 SQL2: select t1.f1,t2.f2 from t1 left join t2 on t1.f1 = t2.f2 where t1.f2=1 and t1.f3=0 The difference is where and on clause, is it returning same…
SleeplessKnight
  • 2,125
  • 4
  • 20
  • 28
29
votes
2 answers

Rails "find_all_by" vs ".where"

I have the following code: def maturities InfoItem.find_all_by_work_order(self.work_order).map(&:maturity) end I was thinking about changing it to: def maturities InfoItem.where(work_order: self.work_order).map(&:maturity) end Would there be…
ardavis
  • 9,842
  • 12
  • 58
  • 112
28
votes
4 answers

C# Linq: Combine multiple .Where() with an *OR* clause

I have been searching a lot about my current problem but I could not find a real answer to solve that issue. I am trying to build a LINQ Query that produces the following SQL: SELECT * FROM TABLE WHERE (Field1 = X, Field2 = Y ... ) or (Field3 =…
thelostcode
  • 331
  • 1
  • 3
  • 10
28
votes
5 answers

Is there a way to ensure WHERE clause happens after DISTINCT?

Imagine you have a table comments in your database. The comment table has the columns, id, text, show, comment_id_no. If a user enters a comment, it inserts a row into the database | id | comment_id_no | text | show | inserted_at | | -- |…
RobStallion
  • 1,624
  • 1
  • 15
  • 28