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
930
votes
22 answers

SQL JOIN - WHERE clause vs. ON clause

After reading it, this is not a duplicate of Explicit vs Implicit SQL Joins. The answer may be related (or even the same) but the question is different. What is the difference and what should go in each? If I understand the theory correctly, the…
BCS
  • 75,627
  • 68
  • 187
  • 294
563
votes
15 answers

How to make "case-insensitive" query in Postgresql?

Is there any way to write case-insensitive queries in PostgreSQL, E.g. I want that following 3 queries return same result. SELECT id FROM groups where name='administrator' SELECT id FROM groups where name='ADMINISTRATOR' SELECT id FROM groups…
Jame
  • 21,150
  • 37
  • 80
  • 107
285
votes
18 answers

What is the difference between HAVING and WHERE in SQL?

What is the difference between HAVING and WHERE in an SQL SELECT statement? EDIT: I have marked Steven's answer as the correct one as it contained the key bit of information on the link: When GROUP BY is not used, HAVING behaves like a WHERE…
ColinYounger
  • 6,735
  • 5
  • 31
  • 33
281
votes
9 answers

SQL - HAVING vs. WHERE

I have the following two tables: 1. Lecturers (LectID, Fname, Lname, degree). 2. Lecturers_Specialization (LectID, Expertise). I want to find the lecturer with the most Specialization. When I try this, it is not working: SELECT L.LectID, …
Adam Sh
  • 8,137
  • 22
  • 60
  • 75
275
votes
7 answers

WHERE vs HAVING

Why do you need to place columns you create yourself (for example select 1 as "number") after HAVING and not WHERE in MySQL? And are there any downsides instead of doing WHERE 1 (writing the whole definition instead of a column name)?
baloo
  • 7,635
  • 4
  • 27
  • 35
239
votes
7 answers

Left Join With Where Clause

I need to retrieve all default settings from the settings table but also grab the character setting if exists for x character. But this query is only retrieving those settings where character is = 1, not the default settings if the user havent…
Sein Kraft
  • 8,417
  • 11
  • 37
  • 39
221
votes
7 answers

Select records from NOW() -1 Day

Is there a way in a MySQL statement to order records (through a date stamp) by >= NOW() -1 so all records from the day before today to the future are selected?
user1092780
  • 2,291
  • 3
  • 15
  • 10
218
votes
15 answers

Detect if value is number in MySQL

Is there a way to detect if a value is a number in a MySQL query? Such as SELECT * FROM myTable WHERE isANumber(col1) = true
Urbycoz
  • 7,247
  • 20
  • 70
  • 108
212
votes
17 answers

How to use NULL or empty string in SQL

I would like to know how to use NULL and an empty string at the same time in a WHERE clause in SQL Server. I need to find records that have either null values or an empty string. Thanks.
poshan
  • 3,069
  • 5
  • 20
  • 30
171
votes
6 answers

Does the order of where clauses matter in SQL?

Let's say I have a table called PEOPLE having three columns, ID, LastName, and FirstName. None of these columns are indexed. LastName is more unique, and FirstName is less unique. If I do two searches: select * from PEOPLE where FirstName="F" and…
ZZZ
  • 3,574
  • 10
  • 34
  • 37
161
votes
10 answers

SQL : BETWEEN vs <= and >=

In SQL Server 2000 and 2005: what is the difference between these two WHERE clauses? which one I should use on which scenarios? Query 1: SELECT EventId, EventName FROM EventMaster WHERE EventDate BETWEEN '10/15/2009' AND '10/18/2009' Query…
Shyju
  • 214,206
  • 104
  • 411
  • 497
159
votes
3 answers

MySQL join with where clause

I have two tables I want to join. I want all of the categories in the categories table and also all of the categories subscribed to by a user in the category_subscriptions table. essentially this is my query so far: SELECT * FROM categories LEFT…
mmundiff
  • 3,875
  • 7
  • 32
  • 46
158
votes
8 answers

Laravel where on relationship object

I'm developing a web API with Laravel 5.0 but I'm not sure about a specific query I'm trying to build. My classes are as follows: class Event extends Model { protected $table = 'events'; public $timestamps = false; public function…
Lic
  • 1,757
  • 3
  • 14
  • 16
157
votes
8 answers

Linq: What is the difference between Select and Where

The Select and Where methods are available in Linq. What should every developer know about these two methods? For example: when to use one over the other, any advantages of using one over the other, etc.
SBurris
  • 7,378
  • 5
  • 28
  • 36
144
votes
5 answers

Haskell: Where vs. Let

I am new to Haskell and I am very confused by Where vs. Let. They both seem to provide a similar purpose. I have read a few comparisons between Where vs. Let but I am having trouble discerning when to use each. Could someone please provide some…
user295190
1
2 3
99 100