Having trouble trying to query AND and OR in an SQlite3 statement. Is there a way where I can do something like WHERE section = ? AND LEVEL =? AND subj1 =? AND subj2=? AND subj3 =? From what I see in this particular line It won’t work because after ‘AND subj1 =?’ SQlite3 now chooses to select whatever subject
Tag: where-clause
Get rows which contain exactly one special character
I have a SQL query which returns some rows having the below format: How can i filter to get rows which only have the format of ‘DB_host’ (place a condition to return values with only one occurrence of ‘_’) i tried using [0-9a-zA-Z_0-9a-zA-Z], but seems like its not right. Please suggest. Answer One option would be using REGEXP_COUNT and at
Conditional query with a parameter stored procedure
I’m learning SQL so I don’t know yet all the subtlety of the language, I wrote the following stored procedure (simplified here): But it doesn’t look like a natural way to do that and there is a lot of repeated code. I want to avoid something like But if it’s the only way. I don’t know the correct tag but
filter timestamp column in SQL Oracle
I have a table with a Timestamp column which I need to filter after ‘2020-08-26’, but every solution won’t work RUN_TIME 2020-07-22 04:22:07 2020-07-22 04:34:07 2020-07-22 04:45:07 2020-07-22 04:50:07 …
How to speed up sql query execution?
The task is to execute the sql query: select * from x where user in (select user from x where id = ‘1’) The subquery contains about 1000 id so it takes a long time. Maybe this question was already …
Get rows with a condition
Each customer can have one or multiple accounts (account_id) How can I get max closed_date for the customers who closed all their accounts and the rest of the active customers?* *active customers are …
postgres sql query to convert group by result in multiple columns
I have two tables financial_account having columns account_name financial_transaction having columns transaction_date,transaction_type, transaction_amount I need data as SUM(transaction_amount) …
SQL query is only returning one entry, when it should be returning several
I am creating a book tagging system and I am trying to call all the books with the same tag. My query is only turning up the first book, and not any of the following books with the same tag. Here is …
Case expression with Boolean from PostgreSQL to SQL Server
I am translating a query from PostgreSQL to SQL Server. I didn’t write the query in PostgreSQL and it’s quite complicated for my knowledge so i don’t understand every piece of it. From my understand: …
Joining table which may not exist with where clause
I have two tables. Let’s say they are: I’d like to make a join to get customer name, number of orders which he/she has finished and sum of money which he/she has spent in total So I’m making this SQL query: If a customer has any finished orders then it will get everything right. But if there are no orders