Questions tagged [where]

The `WHERE` clause is used to specify criterion for retrieval or modification of rows from objects in a database.

Filter by
Sorted by
Tagged with
53 votes
2 answers
132k views

selecting where two columns are in a set

This might be a silly question, and my suspicion is that I can't do this, but is there a construct in SQL that would allow me to do something like the following: SELECT whatever WHERE col1,col2 IN ((...
James's user avatar
  • 655
43 votes
4 answers
61k views

Using column alias in a WHERE clause doesn't work

Given a table users with two fields: id and email. select id, email as electronic_mail from ( select id, email from users ) t where electronic_mail = '' Postgres complains that: ...
Victor's user avatar
  • 567
3 votes
4 answers
3k views

Building where clause based upon parameters

In PostgreSQL I am trying to build a where clause in a function that uses an inbound parameter to determine the contents of the IN For example: select fld1, count(fld1) from xyz where fld1 in ( ...
user110735's user avatar
7 votes
4 answers
27k views

Building Dynamic Oracle Where Clause

I'm working on application that uses dynamic query to do a select statement based on user input, after discussing security with DBAs they want me to convert my dynamic select statement into Stored ...
Vladimir Oselsky's user avatar
1 vote
1 answer
3k views

Error 1052 Field is Ambiguous using Inner Join Function

Error '1052' Field is ambiguous. I understand the error that is happening, and I've looked at several places for the fix and then applied the inner join function in attempt to fix it. It's still not ...
Konfu Chicken's user avatar
7 votes
1 answer
18k views

How do I query PostgreSQL enums like in MySQL?

With the following table in MySQL: CREATE TABLE bob(foo ENUM('a','b','c')); INSERT INTO bob (foo) VALUES ('a'),('b'),('c'),('a'),('a'); SELECT * FROM bob WHERE foo >= 2; +------+ | foo | +------...
user3112092's user avatar
2 votes
1 answer
3k views

MySQL / MariaDB : Many indexes vs. One multi-column index

I need to optimize my MariaDB tables index. I've read a lot of very interesting things on StackExchange, but I'm not sure to have the answer for my case. In my case, I have a table named TableA which ...
Joffrey's user avatar
  • 35
1 vote
1 answer
179 views

Oracle: How can I create a where clause programmatically?

Suppose I have a table like: TBL_CONDITIONS | ID | WHERE_CLAUSE | |----|---------------------------------------| | 1 | fruit = 'apple' | | 2 | ...
scuba_mike's user avatar
0 votes
1 answer
936 views

Is there any better way to list all the databases in Postgres except database named postgres?

SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn = true And datname NOT IN ('postgres') Using the code above, I get all the databases except postgres as shown in the image ...
hunterex's user avatar
  • 147