Questions tagged [where]
The `WHERE` clause is used to specify criterion for retrieval or modification of rows from objects in a database.
172 questions
1 vote
1 answer
144 views
SELECT with array values on WHERE using postgres
I'm using an query to update a object array inside a jsonb column. Example data: [ { "_id": "68696e0a3aab2f9ff9c40679", "altura": 1, "comprimento":...
1 vote
1 answer
101 views
Why do variables in the WHERE clause cause the execution time to balloon [duplicate]
I have a t-sql query that executes hourly, pulling in a variable amount of data depending on the current time when the query executes, i.e.: if it is executing between midnight and 2 AM local time (7 ...
0 votes
1 answer
54 views
JOIN vs. WHERE Special Case - Single Target Foreign Key
Consider: table A with primary key "id" and unique key "name" table B with foreign key "aid" referencing A."id" function (plpgsql) "f_name2id" taking ...
0 votes
3 answers
74 views
Select object from first table, who doesn`t have true in second
I have table with objects uuid name 98665e5a-e1cb-4bf7-93fa-a8d13983f358 object and another table with information about enabled this object and another object together uuid_from_table_upper enabled ...
1 vote
1 answer
71 views
Which indexes create to speed up a query with where
I have a query but I do not know which index create to speed-up it. This is the query: select `id_my_table` from `my_table` where now() between created_data and ifnull(finish_data, now(...
1 vote
0 answers
86 views
unique key on varchar is ignored for maria db
I have the following table: | s3entry | CREATE TABLE `s3entry` ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `S3KEY` varchar(1024) DEFAULT NULL, `FETCHESSINCELASTS3FETCH` int(11) DEFAULT NULL, `...
0 votes
1 answer
74 views
SELLECT * FROM Table WHERE name=$variable not working
I'm trying to set up a simple SQL Code to collect a users details when they log in to a new site I'm writing, but it throws an error every time. Any Ideas what. I'm doing wrong? $sql = "SELECT * ...
0 votes
1 answer
56 views
Can conditionals be used in a WHERE condition?
I am working on something and found this SQL that I am not sure how to rewrite correctly, meaning using PHP PDO. The SQL looks like: $sql = 'SELECT * FROM table WHERE column ' . isset($variable) ? . '=...
0 votes
1 answer
110 views
Group by a column and select the group id on condition that applies to all the rows in it
I have the below table CREATE TABLE result( id INTEGER NOT NULL ,cid INTEGER NOT NULL ,aid INTEGER NOT NULL ,agid INTEGER NOT NULL ,ft INTEGER NOT NULL ,ct INTEGER ...
2 votes
1 answer
126 views
How to use aggregate column in where clause when using group by
I've following table CREATE TABLE `books` ( `book_id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(100) DEFAULT NULL, `author_fname` varchar(100) DEFAULT NULL, `author_lname` varchar(100) ...
0 votes
2 answers
182 views
How to use a WHERE clause with a GROUP BY
I'm learning SQL so apologies if this is too basic a question. I can't seem to figure out how to use a WHERE clause after I GROUP BY a field. For example, how would I filter the results using a WHERE ...
0 votes
1 answer
61 views
How to query in the given order
select * from table where options=(10,223,43,1,23,54,323,32) But the result is not coming in the given order of options. Options need to be changed frequently.
0 votes
2 answers
244 views
Selecting last value to be entered each month
I am looking to pull a closing balance from the database for each month. I have tried SELECT CloseBal As 'Balance', MONTHNAME(DateTime) as 'Month', DateTime FROM Table1 WHERE MAX(DateTime) Group By ...
1 vote
1 answer
8k views
How do I query only rows where multiple instances with the same ID exist with Postgres?
I have a table where I want to gather some statistics, but only for items that are repeated two or more times. Here is how the a simplified table looks like: CREATE TABLE test ( id bigint, ...
0 votes
1 answer
2k views
Which database scheme will be better for dating app performance?
I'm creating dating app like Tinder with Spring Boot and want to make sure that even with huge amount of data it will be working with best possible performance. My tables looks like above. All tables ...