Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL中的组_CONCAT()在插入从另一个表中选择的值时不工作_Php_Mysql_Sql_Database - Fatal编程技术网

Php MySQL中的组_CONCAT()在插入从另一个表中选择的值时不工作

Php MySQL中的组_CONCAT()在插入从另一个表中选择的值时不工作,php,mysql,sql,database,Php,Mysql,Sql,Database,我想用where子句将用逗号分隔的ID从一个表插入到另一个表中。SELECT语句工作正常,但在插入指定关键字时,它只返回1id 我的表格结构: 表1 id property_id keyword (auto-increment) (separated by commas from table 2 where keyword matc

我想用where子句将用逗号分隔的ID从一个表插入到另一个表中。SELECT语句工作正常,但在插入指定关键字时,它只返回1id

我的表格结构:
表1

     id                               property_id                                                 keyword
(auto-increment) (separated by commas from table 2 where keyword matches)  (matched keyword with the description column in table 1 with like clause)
表2

id    property_name       city      country   property_address  property_description
1   Ashish JK Apartments Bangalore  India       Thubarahalli    A Tranquil - Soul Inspiring abode is just waiting for you. Come make the Most of it. 2 BHK Ashish J K Apartment: Total No. of Flats in the Project - 216 A house is the starting point of a new journey through life. The house becomes a reflection of ourselves because we base our lives around it. We see our lives pass by and our children grow up. And all these memories accumulate and make our house a home. It has been designed keeping us as individuals in mind. We all are different. We have our own unique sensibility that is why when we built Aashish J K Apartments we thought of it as a canvas, a canvas you could paint your life on. we did that by building a house that requires, minimum maintenance, with all the systems has been designed to work in a harmonious manner that ensures you a get a good night's sleep, every night Aashish J K Apartments: Seated Between Marathalli and Whitefield, an area that is fast escalating in the property market. Aashish J K apartment is indeed a wise investment to make from the business point of view. It shares its neighborhood with ITPL, Oracle, IGate, HUL, AAI and Other IT Parks located in a very prime place. This location today is a seat of contention for many of Bangalore's real estate developers. One thing that all of us can agree on, is that we all want value for money, and we are sure you would love to know just what Aashish J K Apartments would offer to you and your loved ones within your Pocket limits.
2   Aban Essence         Bangalore  India       Sarjapur Road   A home is not just a structure, it is a part of a flourishing future and the roof that keeps the present intact. We understand this well and hence the apartments are equipped with all the necessary amenities for a family, like swimming pools, gym, club houses, jogging track, garden etc. Along with this beauty are the ample number of trees and plants in the properties. At aban you will find a happy and a peaceful living with luxury and security
所以,在表1中,我基本上想知道表1实际有7000个数据:

id   property_id   keyword
1    1,2           Bangalore
我试过了:

insert into TABLE_1(property_id,keyword) 
SELECT group_concat(id separator ','),'Bangalore' from TABLE_2 AS a
WHERE a.description like '%Bangalore%' OR a.city like '%Banglore%' group by 'Bangalore';
个人SELECT语句运行良好,返回正确结果, 但是当我使用INSERT语句时,它只是返回表2,第一个id与关键字匹配。i、 e:

运行查询后的表2

id property_id keyword
1  1           Bangalore
现在,如何在property\u id列中获取逗号分隔的id,就像SELECT语句返回的那样。 我从昨天起就一直坚持这样做,只发现了类似的更新。但没有正确插入的内容。
我知道在哪里子句首先起作用,然后GROUP_CONCAT(),但是如何使用INSERT获得这样的结果呢?
非常感谢您的帮助。

应该是

insert into TABLE_1(property_id,keyword) 
SELECT group_concat(id),'Bangalore' from TABLE_2 AS a
WHERE a.description like '%Bangalore%' OR a.city like '%Banglore%' 
试试这个

INSERT INTO TABLE_1(property_id, keyword)
( 
    SELECT GROUP_CONCAT(DISTINCT id separator ','), 'Bangalore' FROM TABLE_2
    WHERE description LIKE '%Bangalore%' OR city LIKE '%Banglore%' 
)

我也试过。。在这里,相应的SELECT语句也可以正常工作,即
SELECT group\u concat(id),表2中的“Bangalore”作为WHERE a.description(如“%Bangalore%”或a.city(如“%Banglore%”)插入时不提供逗号分隔的id,只返回与关键字匹配的第一个id。表1的属性id的数据类型是什么?属性id是bigint(20)bigint如何接受逗号分隔的值?它应该是varchar(8000),并且应该是fine。目标表中属性id字段的类型是什么?结果仍然相同:(它只返回一个id将您的table1属性\u id类型从整数更改为字符串谢谢兄弟您节省了我所有的精力。我将它标记为已回答。但您能否解释一下为什么它不适用于整数?因为您的逗号分隔列表是一个字符串。整数“仅为数字”不允许有逗号:)对不起,糟糕的英语没问题我明白你的意思了。所以基本上只是因为逗号,它的行为就像一个字符串,对吗?我会记住这一点