compare products with same option

hi i designed a database for eshop  . i have two table one of them is products and it has id,code,name columns and the oher one 

is option with id,proid,option,optiondes column. and there is a relationship with id from products to proid in option table.

i want to make query that results is compare two or more products with the same option column . please help me 

my english speaking is too bad . please forgive me for this. thank you

September 11th, 2015 4:59pm

Take a look at this article

 T-SQL: Relational Division

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 5:19pm

See those examples posted by Celko long time ago

CREATE TABLE PilotSkills 
(pilot CHAR(15) NOT NULL, 
 plane CHAR(15) NOT NULL, 
 PRIMARY KEY (pilot, plane));

PilotSkills 
pilot    plane 
=========================
'Celko'    'Piper Cub'
'Higgins'  'B-52 Bomber'
'Higgins'  'F-14 Fighter'
'Higgins'  'Piper Cub'
'Jones'    'B-52 Bomber'
'Jones'    'F-14 Fighter'
'Smith'    'B-1 Bomber'
'Smith'    'B-52 Bomber'
'Smith'    'F-14 Fighter'
'Wilson'   'B-1 Bomber'
'Wilson'   'B-52 Bomber'
'Wilson'   'F-14 Fighter'
'Wilson'   'F-17 Fighter'

CREATE TABLE Hangar
(plane CHAR(15) NOT NULL PRIMARY KEY);

Hangar
plane 
=============
'B-1 Bomber'
'B-52 Bomber'
'F-14 Fighter'

PilotSkills DIVIDED BY Hangar
pilot
=============================
'Smith'
'Wilson'

SELECT DISTINCT pilot  
  FROM PilotSkills AS PS1
 WHERE NOT EXISTS 
       (SELECT *
          FROM Hangar
         WHERE NOT EXISTS 
               (SELECT *
                  FROM PilotSkills AS PS2
                 WHERE (PS1.pilot = PS2.pilot)
                   AND (PS2.plane = Hangar.plane)));
---
SELECT PS1.pilot 
   FROM PilotSkills AS PS1, Hangar AS H1
  WHERE PS1.plane = H1.plane
  GROUP BY PS1.pilot 
 HAVING COUNT(PS1.plane) = (SELECT COUNT(plane) FROM Hangar);

September 13th, 2015 6:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics