#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    424
    Rep Power
    8

    Multiple values in SQL column


    Hi,

    I was thinking about a search option where you can search for one or more keyword(s) stored in a table. I don't know how much keywords there will be but there could be a maximum number. So it would be great if I could just get all the values and store them in one column keywords.

    Is this even possible? If yes, how do I do this?

    Thanks in advance
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    storing multiple values in a column is wrong in the relational model. Look up the concept of normalization, especiall the first normal form.

    To assign multiple keywords to multiple entities (whatever those are), you need one table for the keywords and one table for assigning keywords to entities.

    Let's say the keywords belong to products:

    Code:
    products
    - product_id
    - ...
    
    keywords
    - keyword
    
    product_keywords
    - product_id, references products (product_id)
    - keyword, references keywords (keyword)
    To get all products for a given keyword, you use a join:

    sql Code:
    SELECT
    	...
    FROM
    	products
    	JOIN product_keywords USING (product_id)
    WHERE
    	product_keywords.keyword = 'whatever'
    ;
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    424
    Rep Power
    8
    Ok, thanks for the quick response and explanation.

    Something else, I used to get emails from devshed when someone replied to a thread, but lately I haven't receive any on the newer threads but I still do on the older ones (like the thread 'How to make a basic but secure login-system'). Do you have the same problem? It didn't go to the spam, I use the same mail and I didn't change anything in the 'notification' in the threads.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,002
    Rep Power
    9398
    If the replies come close to a time when you're active on the site then they might not send. And I can confirm it does look like you're subscribed to this thread.

    If it's definitely not sending the notifications then mention it in Suggestions & Feedback.

IMN logo majestic logo threadwatch logo seochat tools logo