What I am trying to do is something like this :
我想做的是这样的:
INSERT INTO LIVRE (id_livre, id_client, id_produit)
VALUES (
null,
SELECT id_client from CLIENT where distributeur like "%Traffic%",
SELECT id_produit from PRODUIT where num_serie_produit = 1401000
);
Is it possible with 1 SELECT ?
是否可以有一个选择?
I tried something like :
我尝试过:
INSERT INTO LIVRE (id_livre,id_client,id_produit)
SELECT
null,
C.id_client,
P.id_produit
FROM
LIVRE, CLIENT C, PRODUIT P
WHERE
C.distributeur like "%Traffic%"
AND P.num_serie_produit = 1401000;
but I dont know how to write it correctly :/
但是我不知道怎么把它写对
I searched but I couldn't find really what i want. So sorry if someone already asked it.
我找了找,但我真的找不到我想要的。如果有人已经问过了,很抱歉。
Thanks.
谢谢。
1 个解决方案
#1
3
Use something similar to.
使用类似。
INSERT INTO c (aID, bID)
SELECT a.ID, B.ID
FROM A, B
WHERE A.Name='Nisha'
AND B.Class='Java';
In your case, it would be: (JUST REMOVE LIVRE FROM WHERE CLAUSE)
在您的例子中,应该是:(从WHERE子句中删除LIVRE)
INSERT INTO LIVRE (id_livre,id_client,id_produit)
SELECT null, C.id_client,P.id_produit
FROM CLIENT C, PRODUIT P
WHERE C.distributeur like "%Traffic%"
AND P.num_serie_produit = 1401000;
Assuming that there will be only one row returned from select query,If more than 1 row returned by select query, then use rownum or limit function as appropriate to below query.
假设select查询只返回一行,如果select查询返回的行超过一行,则根据下面的查询使用rownum或limit函数。
INSERT INTO LIVRE (id_livre, id_client, id_produit)
VALUES
(null,
(SELECT id_client from *CLIENT* where distributeur like "%Traffic%"),
(SELECT id_produit from *PRODUIT* where num_serie_produit = 1401000) );
#1
3
Use something similar to.
使用类似。
INSERT INTO c (aID, bID)
SELECT a.ID, B.ID
FROM A, B
WHERE A.Name='Nisha'
AND B.Class='Java';
In your case, it would be: (JUST REMOVE LIVRE FROM WHERE CLAUSE)
在您的例子中,应该是:(从WHERE子句中删除LIVRE)
INSERT INTO LIVRE (id_livre,id_client,id_produit)
SELECT null, C.id_client,P.id_produit
FROM CLIENT C, PRODUIT P
WHERE C.distributeur like "%Traffic%"
AND P.num_serie_produit = 1401000;
Assuming that there will be only one row returned from select query,If more than 1 row returned by select query, then use rownum or limit function as appropriate to below query.
假设select查询只返回一行,如果select查询返回的行超过一行,则根据下面的查询使用rownum或limit函数。
INSERT INTO LIVRE (id_livre, id_client, id_produit)
VALUES
(null,
(SELECT id_client from *CLIENT* where distributeur like "%Traffic%"),
(SELECT id_produit from *PRODUIT* where num_serie_produit = 1401000) );