Replies To: Sql - Find A Value From A List

Re: Sql - Find A Value From A List

Posted 18 March 2005 - 09:52 AM

The proper way to do this would be to break the area id data into a second table. Let's say your current table is table1 with primary key key1. Make a second table areaTable with foreign key areaKey and an area_id column. Now when you want to know what area_ids a row in table1 has, do a join on the two tables:

Incidentally, the above process is called normalization. There are several different levels of normalization increasing in restrictions, from first normal form to fifth normal form. What I described above fulfills first normal form. You can find more information on normalization here: http://dev.mysql.com...malization.html

Re: Sql - Find A Value From A List

Posted 18 March 2005 - 09:54 AM

Hmm...with multiple entries in each field, you may be stuck with the LIKE as a simple statement...the IN statement does what you'd like, but is meant for the other situation (multiple possibilities, one field value)...if this is part of a program/scritp, you can use that languages string manipulation functions to conver the field value to a string, specify what you want, then reconvert to a number, although that is probably not required as I expect the multiple value field is a text string anyway.

[edit]malkiri beat me to it, and his normalization suggestion is the proper way to go...my suggestion is meant for those who do not want to change the db table structure...[/edit]