Jump to content

Add to end of row


slj90
Go to solution Solved by mac_gyver,

Recommended Posts

you can use an UPDATE query with the CONCAT() function to do that.

 

i hope you are not planning on using this to build a delimited list in a column in a database table?

 

Yes that is what I was going to use it for. Why wouldn't you suggest this and what other ways are there? I am using it to keep track of usernames that have "liked" a status.

 

Thanks,

Link to comment
Share on other sites

  • Solution

making a list in a column will require a lot of extra code and queries in order to store values (you must insure they don't already exist in the list), find values, and delete values.

 

the correct method is to have a table that contains one row for each data value. the table would have columns for an id, a 'parent' id (what is being liked), and a 'child' id (who liked it.)

 

the combination of the parent and child id columns would be defined as a unique key. this will enforce uniqueness in the values. to insert a value, you can just insert the new row. if the insert fails with a duplicate key error, you will know that the combination already existed. to find any or all likes by any one or every one, you just query for the child id you want or order by the child id to get all rows by each id together (you would group by the parent or child ids if interested only in a count of likes for an item or a count how many likes someone has given.) to delete any row or rows, you can reference them either by their id, or by the parent id, or the child id values.

 

also, to get the list of actual information, you would use a JOINed query between the above described table and the tables holding the information about the parent and child id's (even if those happen to be the same table, such as a user information table.)

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.