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

Selections through SQL

I am attempting to create a list of all orders that contain six specific products. The current query I'm using is: SELECT o.order_date, o.price AS revenue, o.cost, f.id AS fileid, o.id AS orderid, o.fk_order_status_id, …
Jordyn
  • 1
  • 1
-1
votes
2 answers

Update a row if a field is a subsequence of a string

I have a string S = "1-2-3-4-5-6-7-8" This is how my database table rows look like: id SubSequence 1 1-2-4-5 2 1-3-4-5 3 2-5-7-8 4 5-8-9-10 5 6-7-10-11 and so on ... I want to write a query that would update (in this example)…
-1
votes
1 answer

MySQL query to fetch posts that all users seen

I need to fetch posts that all users seen from MySQL database contains users, posts and users_seen_posts tables. users_seen_posts table: id | user_id | post_id | --------------------------- 1 | xxxxx4 | xxxxx1 | 2 | xxxxx3 | xxxxx6 …
phper
  • 181
  • 2
  • 12
-1
votes
1 answer

Get job title's that work in all deparments SQL

I am currently struggleling determining which jobs exist in all departments. The given table is this one. I have the feeling that this is actually very simple, but I can't figure out how to do it. The problem is basically, that only the jobs…
Timmske
  • 115
  • 1
  • 6
-1
votes
5 answers

How to check if a set is a subset of another set in sql

Text to DDL: CREATE TABLE Recipe1( Ingredient varchar(10) ); INSERT INTO Recipe1(Ingredient) VALUES('Flour'),('Egg'),('Sugar'); CREATE TABLE Recipe2( Ingredient varchar(10) ); INSERT INTO Recipe2(Ingredient) VALUES('Egg'),('Sugar'); I want…
Shayan
  • 709
  • 1
  • 15
  • 31
-1
votes
1 answer

Select with multiple conditions from a single user

I want to do a search of all the users who have taken the same exams as me in a database (MySql). The structure of the database is id, user_id, exam_id and date Well, I have done the exams with the id 5,8,9, I want to know how many have done the…
-1
votes
3 answers

Select only entities with n relations from an n:m relationship

I have an m:n relationship of images and tags in my database, which uses a crosstable to model this. Table imgs contains much more information than just img_id, but that is all that's required to uniquely identify an image. I want to find every…
CrystalRain
  • 72
  • 10
-1
votes
1 answer

Is there a way to get duplicate values in a column with specific values in another column?

I have an sql table like this: TABLE: Info ID | JOB | Value --------|----------|------------------ 1 | leader | 3 2 | Host | 212 1 | User | 4 2 | leader | 5 2 | Host | 4 I'm trying to…
-1
votes
2 answers

Query to find courses that all members are enrolled in

I have a database which contains 5 tables. CREATE TABLE COURSES ( CourseID INT PRIMARY KEY, CourseName VARCHAR(100), Credit NUMBER(10,2) ); CREATE TABLE TEACHERS ( SSN VARCHAR(100) Name VARCHAR(100) ); CREATE TABLE OFFER ( …
draculaxx1
  • 17
  • 5
-1
votes
3 answers

Duplicate rows with SELECT with WHERE IN

I have a problem with building a query that would get me unique rows. The situation is: I have a TABLE product like this: id name price ================== 1 bolt 50 2 screw 4 3 hammer 40 4 drill 30 and a TABLE…
-1
votes
2 answers

SQL: Select only if multiple values are IN 1 column from CatalogTable

I would really appreciate if you could help me with the following query; Having the following tables: ---------- **TableResults** ResultId1 ResultId2 ---------- --------------------- **TableResultsPatterns** ResultId1 pattern1 ResultId1 …
viruskimera
  • 193
  • 16
-1
votes
5 answers

How to use AND on the same entity?

I want to get the names of the workers that did orders on day x AND day y. select name from worker, orders where worker.workerid = oders.workerid and date = x and date = y; So I want only to get the workers that did orders on both days.
noxus Nexus
  • 83
  • 1
  • 5
-1
votes
1 answer

Division Operation on Relational Algebra

I have this schema: CLUB(Name, Address, City) TEAM(TeamName, club) PLAYER(Badge, teamName) MATCH(matchNumber, player1, player2, club, winner) Club in TEAM references Name in CLUB; teamName in PLAYER references TeamName in TEAM; Player 1, player 2,…
JimBelushi2
  • 285
  • 1
  • 3
  • 18
-1
votes
2 answers

SQL Query to loop through

I have two tables TravelHistory and LikesToVisit. Both have two fields, SSN and AirportId. What is the query to find if a customer has visited all cities he likes to visit?. Any help is much appreciated.
-1
votes
4 answers

SQL server find Duplicates in column 1 while ask for 2 specific values in column 2

I have a table like this: Id first_name department 1 John IT 2 George Support 3 Jack IT 4 Jack IT 5 George Dev 6 Maria Dev 7 George IT I am trying to get this: Id first_name department 5 …