473,382 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Query like Amazon's "also purchased..."

I have a table "Subscriptions".

Subscriptions contains the columns "ChannelID" & "MemberID".

The "Channels" table contains a column called "Title"

When someone is viewing a channel, I would like to display "Members
who subscribe to this channel also subscribe to ..." and then list the
Titles of 3 or 4 channels ordered by the most popular.

I'm having trouble coming up with the correct MySQL syntax. Has
someone here done something like this before?
Jul 20 '05 #1
2 2046
sks

"Tim Constantine" <sp**@togosolo.com> wrote in message
news:bb**************************@posting.google.c om...
I have a table "Subscriptions".

Subscriptions contains the columns "ChannelID" & "MemberID".

The "Channels" table contains a column called "Title"

When someone is viewing a channel, I would like to display "Members
who subscribe to this channel also subscribe to ..." and then list the
Titles of 3 or 4 channels ordered by the most popular.

I'm having trouble coming up with the correct MySQL syntax. Has
someone here done something like this before?


What do you mean by channel ? If I assume its something like a particular
magazine, then you want to select all the channels people who bought this
channel also bought (self join on your table), then order and choose.
Something like

select s2.ChannelID, count(*) c from subscriptions s1 join subscriptions s2
on s1.MemberID=s2.MemberID and s1.ChannelID!=s2.ChannelID where s1.ChannelID
= ?? group by s2.ChannelID order by c desc limit 5

Try that, its untested but should be a start.
Jul 20 '05 #2
Tim Constantine wrote:
When someone is viewing a channel, I would like to display "Members
who subscribe to this channel also subscribe to ..." and then list the
Titles of 3 or 4 channels ordered by the most popular.


SELECT COUNT(S.MemberID) AS MemberCount, C.Title
FROM Subscriptions S INNER JOIN Channels C ON S.ChannelID = C.ChannelID
INNER JOIN Subscriptions M ON S.MemberID = M.MemberID
WHERE M.ChannelID = ?
GROUP BY S.MemberID
ORDER BY MemberCount DESC
LIMIT 4

Substitute the currently viewed channel ID for the '?' parameter in that
query, and I think that'll work. I tried it out with a set of tables in
the app I'm working on, where my tables have similar relationships to
one another as your tables.

Regards,
Bill K.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: krystoffff | last post by:
Hi I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the...
3
by: Robin Tucker | last post by:
Hi, Can anyone tell me how to select the "most recent" date values from a grouped query? Consider the following: CREATE TABLE . ( NOT NULL , NOT NULL , NOT NULL ) ON This is a...
2
by: Ellen Manning | last post by:
Using A2K. In my table I have the field "Grant" which can have a value or be null. I have a query that counts the number of records and has a Where clause on the Grant field. The query won't...
7
by: | last post by:
I found similiar issues in MS-KB but nothing that helped me; got the Windows and Office updates from the MS website but that hasn't changed the behavior of this problem, and I don't see anything...
9
by: Mike Bridge | last post by:
I am using MS Access 2003, and I typed in a query in SQL view which was working fine. Now when I open it, it gives me the error "Join expression not supported". Apparently, Access "fixed" it for...
0
by: NotGiven | last post by:
I want to add some shopping pages to my site. I'd lilke to use the easiest things possible, thought I am a PHP developer. What's the easiest way to add a "web store" using Amazon web services or...
3
by: Dave | last post by:
http://snipr.com/UltimateHTML
8
geolemon
by: geolemon | last post by:
I'm trying to perform an update, and I can't avoid this error - I've tried this query what must be 5 different very fundamentally different ways now. Arg. I used to be a DBA in large DB2 and SQL...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.