I’m new to SQL and I am trying to write a query on PostgreSQL to find the cust_ID and customer name of each customer at the bank who only has a loan at the bank, and no account. The database schema is: The results should have only these 3 customers: My two attempts for this query are: 1) Where my
Tag: sql-in
Get distinct members for an array of group IDs
I have 3 tables: Scorecard Group Scorecard_Group (Joint table) I am trying to write a query that fulfills the following purpose: Get the list of distinct scorecard ids WHERE Scorecard_Group.groupId IN (Pass array of groupIds) Get all Scorecard.”name” where Scorecard.”id” IN (Array of scorecardIds that we just queries) I am able to achieve this using 2 queries but I would
Changing In to Exists in SQL – with DISTINCT
Having this one: Reading this one: Changing IN to EXISTS in SQL Tried to change it into “Exists”, but produced this and it did not work: The error is 3706: Syntax error: expected something between ‘=’ and ‘DISTINCT’ keyword. Answer You have already redundant code. Inside the IN subquery you are selecting a column from ORGHEADER, so the LEFT join
SELECT from Multiple IF conditions in Where Clause
I have a following query In the above query I need to add IF condition that IF a.Type is Accessories then I need certain a.Brands to select from and if a.Type is Clothing then I need to select from certain a.Brands Answer Use a CASE expression, but you should also write a proper join with an ON clause for the
Deleting records in MySQL WHERE id IN (@VARIABLE) — (2,3,4)
Is there is a way to delete records using WHERE IN @VARIABLE? Create variable: I’m trying to remove concatenated variables from string. The above SQL removes only first element from the list. In this example, list will contain: (2,3,4). Only the record with id = 2 will be removed. Records with id 3, 4 will remain in the table. See
SELECT NOT IN with multiple columns in subquery
Regarding the statement below, sltrxid can exist as both ardoccrid and ardocdbid. I’m wanting to know how to include both in the NOT IN subquery. Answer I would recommend not exists: Note that I changed the table aliases to things that are more meaningful. I would strongly recommend prefixing the column names with the table they belong to, so the
How to have different values of a single column in a condition where in sql?
I write a SQL query to get different sales information about stores. The problem is that I would like to filter and take only some store numbers in my “GL_ETABLISSEMENT” column, if I just do …
Search function on multiple rows in the same table
I’m wondering how do I add more row’s on my search script to be searched. Here’s my php script: As you can see this: I want to it to search on region and rank rows. I tried: …. it’s showing 0 results. Thank you in advance. Answer Is this what you want? This searches for the parameter in both columns
mysql query – clash between not in and/or
I’m trying to get all my products , from A specific categories and without some products from those categories . i did this query: The problem is that i’m still getting products with the string ‘SPLA’ or ‘SA OLP’ – because the NOT IN clash with the categories How to solve it ? Answer As a starter: always use standard
Getting Msg 8623, Level 16, State 1, Line 1 error on a simple select query on one table
How to optimize a simple query that search on one table for IDes that are not a part of a set. I created the following query Be aware that the list includes bit more than 35000 rows. I get the following database error Msg 8623, Level 16, State 1, Line 1 The query processor ran out of internal resources and