我正在尝试根据另一个表中的某些匹配列在一个表中填充表的id,这是我的查询:
INSERT INTO adverts (publication_id) VALUES (SELECT publications.id FROM publications WHERE publications.name LIKE CONCAT ('%', (adverts.publication), '%'));
1064 - 您的SQL语法出错;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 near' SELECT publications.id FROM publications WHERE publications.name 喜欢CONCAT('%'第1行
不确定我在哪里出错,有人可以帮忙吗?
以下是我的2个表结构:
修改
您可以在下面找到这两个表中的一些示例数据,理想情况下我想要实现的是将id
表中的publications
值插入publications_id
中的adverts
表格基于advert.publication
- publications.name
列中是否匹配。
样本数据的文本格式:
广告:
"56d4085e-654c-47e1-86f0-1e7f5850bebe",,"Saturday 27th February 2016","The Daily Telegraph","188833f6-7405-11e6-96f3-0800274f2cef","2016-09-06","pdf/1/a/1a5a83.pdf","0","2016-02-29 08:59:10","2016-09-06 08:31:50"
"56d71a59-60cc-4a9b-9170-0eb15850bebe",,"Sunday 28th February 2016","The Scottish Sunday Mail",,"2016-02-28","jpg/a/8/a8d73b.jpg","0","2016-03-02 16:52:41","2016-03-02 16:53:13"
"56daa0f6-a2c8-4346-ac05-6f825850bebe",,"Saturday 5th March 2016","The Daily Telegraph",,"2016-03-05","pdf/9/e/9eda94.pdf","0","2016-03-05 09:03:50","2016-03-05 09:04:59"
"56daa30b-f8c4-40aa-8197-6f555850bebe",,"Friday 12th February 2016","Daily Star",,"2016-02-12","pdf/9/2/921346.pdf","0","2016-03-05 09:12:43","2016-03-05 09:13:26"
"56daa37c-a46c-4446-9fa5-6f825850bebe",,"Sunday 14th February 2016","Sunday Express",,"2016-02-14","pdf/3/b/3b8fc2.pdf","0","2016-03-05 09:14:36","2016-03-05 09:14:36"
"56daa3ee-441c-4bb0-b9ff-6f555850bebe",,"Saturday 27th February 2016","Daily Express",,"2016-02-27","pdf/e/b/ebb99b.pdf","0","2016-03-05 09:16:30","2016-03-05 09:16:30"
"56daa44f-4124-41bd-bb34-6fb95850bebe",,"Sunday 28th February 2016","Daily Star Sunday ",,"2016-02-28","pdf/1/e/1e412d.pdf","0","2016-03-05 09:18:07","2016-03-05 09:18:07"
出版物:
"000f371a-7405-11e6-96f3-0800274f2cef","The Daily Telegraph","png/6/9/69e409.png","2016-09-06 00:00:00","2016-09-06 07:43:31"
"10895d76-7405-11e6-96f3-0800274f2cef","The Scottish Sunday Mail","jpg/4/1/41b6e6.jpg","2016-09-06 00:00:00","2016-09-06 07:44:02"
"188833f6-7405-11e6-96f3-0800274f2cef","Daily Star","png/d/c/dcb8dd.png","2016-09-06 00:00:00","2016-09-06 07:44:22"
"212778a5-7405-11e6-96f3-0800274f2cef","Sunday Express","gif/5/2/529a66.gif","2016-09-06 00:00:00","2016-09-06 07:45:57"
"2fa48a98-7405-11e6-96f3-0800274f2cef","Daily Express","gif/6/c/6c5be4.gif","2016-09-06 00:00:00","2016-09-06 07:46:19"
"37d0b036-7405-11e6-96f3-0800274f2cef","Daily Star Sunday","png/c/e/ce7c42.png","2016-09-06 00:00:00","2016-09-06 07:46:44"
"3f78db05-7405-11e6-96f3-0800274f2cef","Scottish Daily Mail","jpg/5/c/5caf2f.jpg","2016-09-06 00:00:00","2016-09-06 07:47:10"
答案 0 :(得分:0)
您必须使用<%
String passw1=(String)request.getParameter("pass");
System.out.println("value of passw1"+passw1); // if null let me know
String passw2=(String)request.getParameter("pass1");
System.out.println("value of passw2"+passw2); // if null let me know
if(passw1.equals(passw2)){ //both string match
//your logic
System.out.println("string match");
}
else{
System.out.println("string not match");
}
%>
而不是UPDATE
声明:
INSERT
答案 1 :(得分:0)
正确的语法是:
INSERT INTO adverts (publication_id)
SELECT publications.id
FROM publications join adverts on <condition>
WHERE publications.name LIKE CONCAT ('%', (adverts.publication), '%'));