mysql - Unable to select rows containing multiple values in mysqli -


  create tab 'product' (`product ID ') (10) unsigned not auto_increment,` product name' varchar (100) Null is not default, `hashtag 'varchar (255) .......)  

I have more than one value in the hashtag column Select Single Cell 11,12,13,14

Select the Hashtag from `Product 'where hashtags (11,14);

When I try this query, only that column is selected, which is the first value true with the query for its respective cell, so how do I go ahead?

  + ------------ + | Hashtag + ------------ + | 11,14,12,13. + ------------ + | 13,14,15 + ------------ +  

I want to type the query that has the 14 code with the hashtag

First of all, it is bad to store multiple values ​​in columns! See. Try using

such as operator:

  select the hashtag from the 'product' where hashtags such as '%, 14,%' Or 'hashtag' such as '14%,' or hashtag such as '14,%' or hash tag such as '14'  

Although this is not the best way to maintain your data, its too much The principle is to describe here, but this idea is the following:

Create an additional hashtag (hashtag id, product id) Store a tag for a particular product, which uses your example, and your product assumes that ID is 1, the following lines store similar information in your column hashtag.

  hashtag --------11 | 1 12 | 1 13 1 14 | 1  

Now, use a query for a particular product query with tags 11 and 14:

  SELECT ProductId, productName, .. From the product, hashtag where hashtag.product id = product.product id and hashtaghashtagid = 14 or hashtag id = 13 In fact, this query may be more complicated to ensure that a product has both hash tags but it is original idea. See the link in the first line. 


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -