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
0
votes
2 answers

PostgreSQL - how to query "result IN ALL OF"?

I am new to PostgreSQL and I have a problem with the following query: WITH relevant_einsatz AS ( SELECT einsatz.fahrzeug,einsatz.mannschaft FROM einsatz INNER JOIN bergefahrzeug ON einsatz.fahrzeug =…
Blackbam
  • 17,496
  • 26
  • 97
  • 150
0
votes
2 answers

Many-to-many relation filter

I need to filter my query with categories table which has many2many relation with another table. Is it possible to filter query with many2many relation? Table res_partner has many2many field category_id relating to table…
Andrius
  • 19,658
  • 37
  • 143
  • 243
0
votes
4 answers

SQL query where all A's must have the following coumns from B that are equal?

Here's my specific example of what I mean. I have the following table defined: CREATE TABLE pets ( id INTEGER UNSIGNED NOT NULL, name VARCHAR(20) NOT NULL, breed VARCHAR(20) NOT NULL, color VARCHAR(20) NOT NULL, weight INTEGER…
A_Obregon
  • 51
  • 5
0
votes
1 answer

t - sql how to intersect records with 2 columns

I have 2 columns Config Plant ------ ----- ROC DEP1 RET DEP1 ROC UAP1 RET UAP1 SSL UAP1 ROC PLP2 RET PLP2 How to get records of config which is same for all plants. In this…
Asil Eris
  • 31
  • 3
  • 8
0
votes
2 answers

Need simplify sql query with "count" function and "IN" operator

I have a table only consisting of two columns: ObjectID||PropertyID The task: get the all ObjectID whith PropertyID == (P1 and P2 and P3 and ...). I solved this task: SELECT * FROM ( SELECT SD.ObjectID ObjectID, …
Mitrodan
  • 73
  • 4
-1
votes
1 answer

JOIN of 2 tables where cross all records

Given these 2 tables Table name: MyValues Id IdValue 1 10 2 10 3 10 1 11 Table name: MyConditions Id IdValue 7 10 7 11 How could I write a query to get the Ids from the MyValues table to return the ones that match all…
user441365
  • 3,934
  • 11
  • 43
  • 62
-1
votes
2 answers

How to find other parent table entries that have exact same values and number of child table entries?

SQL: Returning an id from a table based off the values in the child table.(SQL)(MySQL) I have 2 tables, Parent (ID), and Child (Value_A, Value_B, ParentID), with a 1->many relationship (Parent has multiple children). Given an Id for the Parent…
BOOKPURP
  • 9
  • 3
-1
votes
2 answers

How to check whether ALL the rows in a table exist among a list of rows in another table?

For example, I have this table that contains two specific brands - 'Ford' and 'Subaru', which just so happen to be the top earning brands for the Eastern and Western markets respectively. To obtain this info, I make a view: create or replace view…
-1
votes
1 answer

SQL Sakila Query Question - Find all actors that have starred in films of all 16 film categories

I am trying to put together a query from the Sakila database. The query should find all actors that have starred in all 16 film categories. To get all of this information into one table for querying, I have performed a INNER JOIN: SELECT…
-1
votes
1 answer

SQl shorhand for and condition

i'm facing a problem with sql queries... is there a shorthand for AND condition like IN= many OR conditions?? when not, any idea about this situation. considering we have 2 tables student and topics with many to many relation. Problem: get all…
jo stark
  • 11
  • 1
-1
votes
1 answer

How to perform the equivalent of AND amongst search terms

I've built an app that displays images. Each image can be tagged with multiple tags. I've now added a Search box that works fine in an OR kind of way. What I'm trying to figure out with PostrgreSQL is how to also let AND work with the entered…
RobertW
  • 226
  • 1
  • 2
  • 10
-1
votes
2 answers

MySQL - How to get all the results having all of the column values?

I want to get all of the id1 where id2 is equal to 2 and 3. Consider the sample table given below Sample Table- | id1 | id2 | | --- | --- | | 1 | 2 | | 1 | 3 | | 1 | 4 | | 2 | 2 | | 2 | 4 | In this case, expected output is as…
-1
votes
3 answers

find id for which there is atleast one entry in table for every state

I have a table named Users, with userId as one of the column, the user can be in any one of given 5 possible states which are (Unregistered, registered, subscribed, premier, unsubscribed). I want a query which can give me a list of all those userIds…
samar taj Shaikh
  • 1,165
  • 11
  • 18
-1
votes
1 answer

SQL Server Select Query for company that has employee role (Owner and CEO) at the same time

My Table Structure is shown below: I would like to retrieve company names and person names that working for this company and their position are (CEO and Owner), it means that person must be both (CEO and owner). I've tried so far and created below…
-1
votes
2 answers

Find data by multiple Lookup table clauses

declare @Character table (id int, [name] varchar(12)); insert into @Character (id, [name]) values (1, 'tom'), (2, 'jerry'), (3, 'dog'); declare @NameToCharacter table (id int, nameId int, characterId int); insert into @NameToCharacter (id,…
gh9
  • 10,169
  • 10
  • 63
  • 96