Skip to content
Advertisement

Tag: sql-in

SQL query for EXCEPT or NOT IN

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

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 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

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

Advertisement