So if these are your requirements:
- User select a few countries on a web page.
- Countries selected by that user are stored in database.
You need to do the following:
create table country(
Set countryId as a primary key.
create table user(
set userId as a primary key.
Since they are connecting to your page to click on these countries, we can call these "sessions", so new rule:
- Every time a user connects to the web site, a session is logged.
Which then produces this table
create table session(
Set sessionID as a primary key.
Set userID as a Foreign key referencing table user.userId.
Set countryID as a foreign key referencing table country.countryId.
If you want to count how many countries each user has selected in a given session, you would then do the following:
select sessionId,UserId, count(*)
group by sessionId,UserId
If you want to know all countries selected for every time a user went on your web page, group by UserId only.
Again, this is based on very very limited requirements.
You should be able to reuse the concept for your own purpose however.
I hope that helps.