Preserved Topic: MySQL query involving a join and many to many connections. |
|
---|---|
Author | Thread |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 05-09-2001 02:18
Okay, I have a fully optimized database structure. For the sake of simplicity here are the fields from each table that are relevant to the question: code: Event : event_id, title_id
code: SELECT Event.event_id, Title.title FROM Event LEFT JOIN Title USING (title_id) WHERE ???;
|
Paranoid (IV) Inmate From: other places |
posted 05-09-2001 05:38
I'm not totally sure I tracked that whole discussion, but I think I understand you to say you have a bit vector (is that what you mean by boolean array?) representing user selections. Linear likes bit vectors. Bitwise AND is your friend. Represent the sponsor ID as a bit vector also, with just one bit set. The position scheme needs to match the scheme of your other bit vector (obviously). Then your where clause boils down to the bitwise AND of user selections and sponsor ID, and MySQL can do bitwise AND. |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 05-09-2001 20:22
Intriguing concept. I have no practical experience with bit vectors, but I think you are right! I already have implemented the solution with this code: code: for($i = 0; $i < mysql_num_rows($result); $i++) {
|
Paranoid (IV) Inmate From: other places |
posted 05-09-2001 21:13
Yeah, integer or long integer type works just fine. |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 05-09-2001 23:42
Yes. If MySQL implemented subselects it would be easy, but because it doesn't I doubt there is a way to get it into one query. The reason is because it has to check multiple rows in the Event_Sponsor table to see if any of them match up with the selected sponsors. This means that a new bit vector would need to be generated for each event_id in the table. I could use a join of some sort so that it would all be in one table, but it needs to return one and only one row for each event. If I joined, it would return several rows for a single event if it had more than one sponsor. Even if I can return only one row per event, it still would reutnr only the FIRST sponsor, which might not necessarily be one on the list. |