php - Best method for storing multiple ID's in MySQL for querying large result sets -


i save email lists client subscribes to. might have:

email_lists:

id    name 1     coupons 2     monthly newsletter 3     company news 

now, users can subscribe many lists want. let's have 3 users:

users:

id    name    lists 1     bob     1,3 2     jane    2,3 3     tom     1 

now need query user id's subscribed list #1:

select id users lists '%1%' 

is there better way of storing list id's each user queries can performed more efficiently?

a third table subscrib best here:

userid    listid 1         1      // bob, coupons 1         3      // bob, company news 2         2      // jane, monthly newsletter 2         3      // jane, company news 3         1      // tom, coupons 

and query (for company news):

select userid subscrib listid = '3'; 

or

select s.listid, u.email, u.name subscrib s left outer join users u on u.id = s.userid s.listid = '3'; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -