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

In SQL, is there something like "IN", but for multiple "AND" conditions?

In SQL, is there something like "IN", but for multiple "AND" conditions instead of multiple "OR" conditions? EDIT: I see now that this was a foolish question. What I really meant was: If I have a table like this: _id time_entry_id tag_id 1 1 1 2 1…
-1
votes
2 answers

Comparing two or more values in sql

I have a table which has the following. fieldmapid | fieldid ------------+--------- 2010 | 180 2012 | 90 2012 | 92 2020 | 90 2020 | 92 2020 | 95 20005 | 90 …
Nav_cfc
  • 154
  • 1
  • 4
  • 15
-1
votes
2 answers

SQL- Show only users with certain awards

I have an Access user database similar to UserName | Award | DateGiven We assign various types of awards. Each award assignment would have a separate entry. I need to be able to find which users have been assigned 3 specific awards. For…
-2
votes
1 answer

Combine similar EXISTS conditions in PostgreSQL

I would like to know whether multiple similar exists conditions can be combined in a meaningful and performant way. Let us assume the following example: Different activities can be assigned to a service (n-m). Activities can be grouped independently…
-2
votes
3 answers

SQL filter on unknown number of columns

I have table containing products, a table containing tags for the products where each product can have several tags, eg products product_id|name|… 1 |book 2 |game 3 |desk … , tags product_id|tag 3 |used 3 …
chr
  • 101
  • 11
-2
votes
2 answers
-2
votes
3 answers

SQL N To No Releationship Table

I have 3 table by this names Supplier :For store supplier info SupplierID Name 1 Supplier 1 2 Supplier 2 3 Supplier 3 4 Supplier 4 Product : For store product info ProductID Name 1 Product 1 2 Product 2 3 Product…
-2
votes
2 answers

SQL Select from table where joined values from a second table are a subset of values from a third table

I have the following tables in MS SQL Server: Tasks, Users, Tags, TaskTags (maps a task to a tag), and UserTags (maps a user to a tag). Given a User U, I want to find all tasks T where every tag of T is also a tag of U (e.g. a task should be…
ROODAY
  • 756
  • 1
  • 6
  • 23
-2
votes
1 answer

MySQL query with multiple AND statement

I have database table like this: |id |item | |1 |item-1 | |2 |item-1 | |1 |item-2 | |3 |item-3 | |2 |item-2 | |1 |item-3 | How in MySQL get id who hes item-1 AND item-2? This don't work: SELECT id FROM table WHERE item = 'item-1'…
Djuka
  • 1
-2
votes
2 answers

using set operations sql to find common elements

Retrieve IDs, first names, and last names for those artists who have done both paintings and drawings I have tried Joining the tables with: SELECT artist.artist_id, artist.last_name, artist.first_name FROM artist INTERSECT SELECT artwork.artist_id…
-2
votes
6 answers

SQL : join more than one table

Write an sql query to select the names of the students who have attended all the lectures of professor 'JOHN' but not any lecture of professor 'JOSEPH'. I have written this query, but it is giving me the name of student who are taking the lecture…
sparsh610
  • 1,552
  • 3
  • 27
  • 66
-2
votes
2 answers

SELECT requiring multiple joins with one to many tables in PostgreSQL

Toy example: I have a database schema shown in this EDR diagram: Student one-to-many with StudyGroup StudyGroup one-to-many with Borrowed Borrowed one-to-many with Books. I want to get all books that have been borrowed by all study groups of a…
semiphys
  • 7
  • 5
-2
votes
1 answer

select a set of products present in all stores all weeks

I have a database in postgresql with product_id, store_id, week, price_avg, price_min, price_max and I want to select a set of homogeneous products that it is present in a set of stores and in the same weeks. I have tried some approaches but it´s…
ferchu109
  • 1
  • 3
-2
votes
3 answers

Find out if column contains two distinct values for each group

I want to select the rows which satisfy both conditions of the same column. Below is the table schema. Security Table Id RoleId CompId SecurityToken Accesstype 1 1 10 abc 2 2 1 10 xyz …
vishal
  • 65
  • 1
  • 2
  • 13
-2
votes
1 answer

SQL Server, get record which having both skills

I have a employee table and a skill table. In skills table, I have entries like empid skills --------------- 1 C# 1 PHP 2 C# 2 Java Now I want all employee id's which have both C# and Java.
DEV
  • 3
  • 1