I'm sure you are aware that this is a non-normalized database design, and
that those tend to make designing queries more difficult and/or inefficient.

The LIKE operator should give you what you want, but you need to be careful:

(PHP string def:)

$sSQL = "SELECT <list>
FROM <table>
WHERE readBy LIKE '$UserID,%'
OR readBy LIKE '%,$UserID'
OR readBy LIKE '%,$UserID,%'"

You need to look for the three situations to avoid matching the wrong
entries in for example (11,20) (5,11) or (5,11,20).

HTH,
Tore

----- Original Message -----
From: "Rich Hutchins" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 04, 2003 8:42 PM
Subject: Perplexed by reverse SELECT statement.


> Man, this was a tough MySQL question to assign a Subject to. Hopefully the
> answer
> is easier.
>
> I have a table called news which contains a column called readBy. The read
> by column is of type TEXT and it contains a CSV list of IDs of users who
> have read a certain news item. For example, if my user ID is 1 and I have
> read news item 50, the readBy column might look like this: 2,10,9,73,1
>
> When I do a SELECT of all news items from this news table, I want to
select
> only those items that I have not read - ones where the user ID 1 is NOT in
> the readBY column.
>
> I have attempted to pull this off using find_in_set and where not like,
but
> have not been able to get the results I expect. Any advice?
>
> Thanks in advance.
> Rich
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to