Questions tagged [relational-division]

Operation in relational algebra or in an RDBMS (mostly SQL) to partition relations. The inverse of a Cartesian product (CROSS JOIN in SQL).

E.F. Codd identified eight relational algebra operators in his defining paper "A Relational Model of Data for Large Shared Data Banks". Division is the least known and probably most complex of them. It is the inverse operation of a Cartesian product (CROSS JOIN in SQL).

It means partitioning a (bigger) table with rows from another (smaller) table. For requirements like:
"Find tuples that combine a particular value in one attribute with several values in another attribute."

A practical example for a setup with a many-to-many relationship between clubs and people:
"Find all clubs where Sue and John and James are members."

More information

467 questions
-1
votes
3 answers

SQL: Find Items based on their attributes

On PostgreSQL, I have a table item, and a table item_attribute. So an item can have multiple attributes. table: item id name 1 A 2 B 3 C table:…
esskar
  • 10,638
  • 3
  • 36
  • 57
-1
votes
2 answers

SQL select ids with columns that has a least two tags

I am working on job related data and wanted to do some analysis. I have two tables a Job table with job_id and an Application table with app_id,job_id,tag. I want to select all job_ids that have an application with at least one tag with the name ->…
Gary Ong
  • 788
  • 1
  • 5
  • 8
-1
votes
1 answer

SQL how to SELECT an id based on multiple rows conditions

I am working with nodejs and postgresql. My postgresql relation has 3 columns: id lesson_id tag_id. A lesson could belong to 1 or multiple tags. I am trying to select all the lesson whose belongs to the requested tags. For example tags requested…
aviateur22
  • 45
  • 1
  • 8
-1
votes
3 answers

In a nested query, check all values for a condition

How can I get rid of nested queries (agree, dis_agreed)? How to rewrite to join - I can not think of it. Maybe there are other optimal solutions? select * from ( select (select count(id) from Agreement a where a.ConclusionCardFile = f.id…
-1
votes
4 answers

SQL show only results that have both items

I have a SQL table with names and fruits that the persons ate. I only want the result to show the Names of people who ate both an apple and a banana. But if i use "Where Item='Banana' and item='Apple', the data shows nothing. If i use: Where item…
MegaOctane
  • 15
  • 4
-1
votes
3 answers

Select where join match list of value

I'm not sure how to ask this question. I have the following schema : message_id message_content 1 Hello World 2 EHLO message_id concerned_user 1 laura 1 vick 1 john 2 laura 2 vick How to select message_id which…
bux
  • 7,087
  • 11
  • 45
  • 86
-1
votes
2 answers

MySQL Where IN must Match all Values

my sql script : select pack_id from pack_product pp where pp.product_id in (2,1) group by pack_id data example : pack_id | product_id 1 | 1 2 | 1 2 | 2 I want to return only pack_id 2 because match all…
nassim miled
  • 581
  • 1
  • 6
  • 18
-1
votes
4 answers

Show data of Column1 which consists the mentioned values present in column 2

My question is how can I get data of column1 depending on the column2. This is a small example of data that I have stored. create table Student_subject ( Student varchar(20), Subject varchar(20) ) insert into Student_subject values…
MShaikh
  • 1
  • 1
-1
votes
4 answers

Find movies connected to all given tags

I don't know how to phrase my SQL question so I will type out an expected scenario. MovieID TagID 1 1 1 3 1 5 2 1 2 2 2 3 3 1 3 3 3 5 3 7 I want to select movieIds that have tag relationship with at least ALL these tags…
-1
votes
2 answers

Select rows based on matching a column contents across all rows within an identifier in another column?

Running SQL Server 14.0.2037.2 on Windows 10 Enterprise version 21H1 I am trying to return IDs only when another columns entry across all rows within that ID matches the entries of a similar column in a second table, again within specific IDs. For…
user2272413
  • 169
  • 1
  • 1
  • 5
-1
votes
1 answer

SQL: Consolidating similar values of a column in a table and assign them an identifier

I have a table as follows: IndentNo MaterialId ----------------------- 1001 22345 1001 23457 1001 24456 1002 22345 1002 23457 1002 24456 1003 29987 1003 22345 1003 …
pythondumb
  • 1,187
  • 1
  • 15
  • 30
-1
votes
2 answers

Find all jars that have red balls and blue balls

With this simple query I can find the ids of all jars that contain either red balls or blue balls: SELECT id FROM "Jars" J JOIN "Balls" B ON B.jarId = J.jarId WHERE B.color = 'red' OR B.color = 'blue' GROUP BY id How can I find the ids of all jars…
Jazcash
  • 3,145
  • 2
  • 31
  • 46
-1
votes
2 answers

MySQL select all rows with different values same column

I have the following tables: Table configs: id config 1 ip 2 os 3 cpu Table options id config_id option 1 1 127.0.0.1 2 1 192.168.0.1 3 2 windows 4 2 linux 5 3 AMD 6 3 Intel The config_id…
user765368
  • 19,590
  • 27
  • 96
  • 167
-1
votes
3 answers

how to filter Grouped results to match more than one value?

-The question itself might not describe the issue well, but I'm not sure how to present it I have implemented this design ,so I have the following table diagram. +---------------+ +-------------------+ | PRODUCTS |-----< PRODUCT_VARIANTS …
Omar Abdelhady
  • 1,528
  • 4
  • 19
  • 31
-1
votes
3 answers

PostgreSQL IN all

I have the following table structure: | id | object_id | status_id | ------------------------------ | 1 | 12 | 1 | | 2 | 12 | 2 | | 3 | 18 | 5 | I need to select all object_id that were in status 1…
First Sin
  • 94
  • 6