5 messages in com.mysql.lists.mysqlRE: Perplexed by reverse SELECT state...
FromSent OnAttachments
Rich Hutchins04 Mar 2003 17:41 
Beau Hartshorne04 Mar 2003 18:55 
Tore Bostrup04 Mar 2003 19:04 
Rich Hutchins04 Mar 2003 19:19 
Bruce Feist04 Mar 2003 20:54 
Subject:RE: Perplexed by reverse SELECT statement.
From:Rich Hutchins (reh@rochester.rr.com)
Date:03/04/2003 07:19:54 PM
List:com.mysql.lists.mysql

Thanks to Beau and Tore for insightful feedback. I will most likely implement the lookup table logic and do things right from the start rather than using a band-aid solution.

Rich

-----Original Message----- From: Beau Hartshorne [mailto:be@members.evolt.org] Sent: Tuesday, March 04, 2003 9:56 PM To: 'Rich Hutchins' Cc: mys@lists.mysql.com Subject: RE: Perplexed by reverse SELECT statement.

Hi Rich,

I think that instead of a readBY column in your news table, you should use what's called a lookup table. In this case, the lookup table would store the primary key from the news table and the primary key from the user table. Your table structure might look something like this:

user

---------- user_id username password

news

---------- news_id headline body

user_news (the lookup table)

---------- user_id news_id

The data in the user_news table will look something like:

SELECT user_id,news_id FROM user_news;

+---------+---------+ | user_id | news_id | +---------+---------+ | 1 | 2 | | 1 | 10 | | 1 | 9 | | 2 | 23 | | 1 | 23 | +---------+---------+

This means user 1 has read news items 2,10,9 and 23. User 2 has read only news item 23. With this structure, you should be able to build a SELECT query to find the information you need.

Beau

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.

To request this thread, e-mail <mysq@lists.mysql.com> To unsubscribe, e-mail <mysql-unsubscribe-rehptc=roch@lists.mysql.com> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php