> I'm not even sure if I'm naming the question correctly. I hope I can
> ask/explain it clearly enough to get a hint ;)
> 
> Essentially...
> 
> 1) I have a table of portfolio 'pieces', each row of which has a unique ID
> 
> 2) I have a table of 'projects', which are comprised of a number of
> 'pieces'. There is a column in this projects table called 'pieces', which
> contains a delimitated string of all the 'pieces' related to that 'project',
> in the format of '1||2||3||5||12||16||17||24||25'
> 
> 3) When viewing a data sheet of a single row in the table 'pieces', I'd like
> to be able to include a reference to any 'projects' that the said piece may
> be a member of.
> 
> I've tried a few things like
> 
> $ID = '1';
> 
> SELECT * from projects WHERE pieces LIKE '$ID%'
> - which will find anything that starts with $ID, such as
>     1||3||4
> 
> SELECT * from projects WHERE pieces LIKE '%$ID%'
> - which will find anything that contains $ID, such as
>     1||3||4
>     5||1||72||8
>     3||5||21||9
>     3||5||17||9
> 
> What I can't figure out how to do is to select this
>     3||5||1||9
> 
> Without selecting something like
>     3||5||21||9 or
>     3||5||17||9
> 
> Is this possible in a single sql statement, or do I have to select all rows
> of 'projects' and use php to somehow loop through the results, explode the
> delimitated strings, and look for the exact match this way, somehow.
> 
> If you haven't noticed, I'm a little bit of a newbie, so please be nice :)
> 
> Salut,
> verdon
> 

It may be possible to cruft a query for what you want, but I'd suggest a
slight re-design of your tables. Do some reading up on designing
relational databases ("Database design for mere mortals" by Michael J.
Hernandez is an excellent choice. ISBN: 0-201-69471-9).

Any time you have more than one value in a field is an idication you
should consider making that field a separate table. In your case I'd
make a new table of 'pieces' and populate it with something that
identifies which client AND project each piece belongs to. Maybe a
combination of 2 fields (client id + project id). Then your select would
include 2 'where' conditions checking client id and project id.

btw, your email address bounced back - couldn't check the MX records.

-- 
/* All outgoing email scanned by AVG Antivirus /*
Amer Neely, Softouch Information Services
W: www.softouch.on.ca
E: [EMAIL PROTECTED]
V: 519.438.5887
Perl | PHP | MySQL | CGI programming for all data entry forms.
"We make web sites work!"

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to