Help needed!Basic INTERSECT application
Help needed!Basic INTERSECT application
(OP)
Hello!
I've set up a new mini database related to a mini business (for which the tables definition have been appended to this message). Now, I need to know every "IdPro" that is ordered for each client for whom agent "a03" places an order. By the way, "commande" is the same as "order" and "Montant" is the same as "amount". I tried the following querry, but it doesn't work:
SELECT IdPro FROM commande
WHERE IdAge='a03' intersect all
SELECT distinct IdCli FROM commande WHERE IdAge='a03';
So, what's wrong?
Thanks in advance!
P. Délisle
N.B.:
Here's "commande" table definition:
CREATE TABLE commande (
IdCom VARCHAR2(10) NOT NULL,
IdPro VARCHAR2(10),
IdCli VARCHAR2(10),
IdAge VARCHAR2(10),
DateCom DATE,
Qte NUMBER NOT NULL CHECK (Qte > 0),
Montant NUMBER NOT NULL CHECK (Montant > 0),
PRIMARY KEY(IdCom),
FOREIGN KEY(IdPro) REFERENCES produit(IdPro) ON DELETE CASCADE,
FOREIGN KEY(IdCli) REFERENCES client(IdCli) ON DELETE CASCADE,
FOREIGN KEY(IdAge) REFERENCES agent(IdAge) ON DELETE CASCADE
);
IdCom: the ID of the order
IdPro: the ID of the product ordered
IdCli: the ID of the client
IdAge: the ID of the agent
DateCom: the date when the ordered has been done
Qte: the quantity of the product ordered
Montant: the amount of the order (for that product)
I've set up a new mini database related to a mini business (for which the tables definition have been appended to this message). Now, I need to know every "IdPro" that is ordered for each client for whom agent "a03" places an order. By the way, "commande" is the same as "order" and "Montant" is the same as "amount". I tried the following querry, but it doesn't work:
SELECT IdPro FROM commande
WHERE IdAge='a03' intersect all
SELECT distinct IdCli FROM commande WHERE IdAge='a03';
So, what's wrong?
Thanks in advance!
P. Délisle
N.B.:
Here's "commande" table definition:
CREATE TABLE commande (
IdCom VARCHAR2(10) NOT NULL,
IdPro VARCHAR2(10),
IdCli VARCHAR2(10),
IdAge VARCHAR2(10),
DateCom DATE,
Qte NUMBER NOT NULL CHECK (Qte > 0),
Montant NUMBER NOT NULL CHECK (Montant > 0),
PRIMARY KEY(IdCom),
FOREIGN KEY(IdPro) REFERENCES produit(IdPro) ON DELETE CASCADE,
FOREIGN KEY(IdCli) REFERENCES client(IdCli) ON DELETE CASCADE,
FOREIGN KEY(IdAge) REFERENCES agent(IdAge) ON DELETE CASCADE
);
IdCom: the ID of the order
IdPro: the ID of the product ordered
IdCli: the ID of the client
IdAge: the ID of the agent
DateCom: the date when the ordered has been done
Qte: the quantity of the product ordered
Montant: the amount of the order (for that product)
RE: Help needed!Basic INTERSECT application
SELECT * FROM commande WHERE IdAge='a03'
If that does not work, try replacing the equal sign after IdAge with the LIKE statement. I've seen some SQL drivers that will only accept = when comparing two columns or a column to a specific numeric-only value.
Hope this helps!