简体   繁体   English

使用mysql从列中删除特定ID

[英]Delete Particular Id From Column using mysql

Two tables named are image and product the structure of the tables are as below 命名为图像和产品的两个表的结构如下

Table : Image 表:图像

image_id    image_path  image
  1          ./images/   aaa
  2          ./images/   bbb
  3          ./images/   ccc

Table : Product 表:产品

product_id   product_gallery
  1           1,2
  2           3,1
  3           1,2,3

Now I want to remove the image from image table image_id = 3 现在我要从图像表image_id = 3中删除图像

While I'm deleting image id 3 from image table, at the same time product table product gallery column containing the id 3 will be deleted. 当我从图像表中删除图像ID 3时,同时将删除包含ID 3的产品表product gallery列。

For example 例如

Expected output : 预期产量:

   product_id   product_gallery
      1           1,2
      2           1
      3           1,2

I don't have any idea for this but I can delete the images as of now, still I want to delete image id from the product table. 我对此没有任何想法,但是我现在可以删除图像,但是我仍想从产品表中删除图像ID。

It's better to have a 3-rd table , some thing like : 最好有第3张桌子,例如:

Table : product-gallery 表:产品库

   product_id   image_id
      1           1
      1           2
      2           1
      3           1
      3           2

In this way, working with database would be as easy as abc :) 这样,使用数据库就像abc一样容易:)

But if you want to go your way, you have to deal with some sql or php processing functions. 但是,如果您想走自己的路,就必须处理一些sql或php处理功能。

i think it is better if you change the way your product table was constructed.. it would give you a hard time retrieving and manipulating it.. try using this format: 我认为最好更改产品表的构造方式,这将使您很难检索和操作它。尝试使用这种格式:

id product_id product_gallery
1    1          1
2    1          2
3    2          1

etc etc... 等等等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM