Here's how I'd go about this, with an example database script and query:
Create/Load Users Table - Using a surrogate primary key instead of the username since queries will be faster against INTs and they can conceivably change.
CREATE TABLE users (
id int(11) AUTO_INCREMENT NOT NULL,
username varchar(255) NOT NULL,
gender char(1) NULL,
PRIMARY KEY(id)
) ENGINE = MyISAM AUTO_INCREMENT = 3
Load Users
INSERT INTO users(id, username, gender)
VALUES(1, 'john', NULL)
GO
INSERT INTO users(id, username, gender)
VALUES(2, 'jane', NULL)
GO
Create Plants
CREATE TABLE plants (
id int(11) AUTO_INCREMENT NOT NULL,
name varchar(200) NOT NULL,
PRIMARY KEY(id)
) ENGINE = MyISAM AUTO_INCREMENT = 6
Load Plants
INSERT INTO plants(id, name)
VALUES(1, 'fern1')
GO
INSERT INTO plants(id, name)
VALUES(2, 'fern2')
GO
INSERT INTO plants(id, name)
VALUES(3, 'orchid1')
GO
INSERT INTO plants(id, name)
VALUES(4, 'orchid2')
GO
INSERT INTO plants(id, name)
VALUES(5, 'lilly1')
Create Join Table I use a surrogate primary key here since so many web platforms won't properly update a join table with a 2 column primary. Also, I've ended up adding meta data / details to these types of joins quite often, and it gets messy without it. Note I don't restrict the combination of the same user adding the same plant type, but you can easily.
CREATE TABLE plants_users (
id int(11) AUTO_INCREMENT NOT NULL,
plant_id int(11) NOT NULL,
user_id int(11) NOT NULL,
PRIMARY KEY(id)
)
ENGINE = MyISAM
AUTO_INCREMENT = 8
GO
CREATE INDEX fk_plant_id USING BTREE
ON plants_users(plant_id)
GO
CREATE INDEX fk_user_id USING BTREE
ON plants_users(user_id)
Load Join Table
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(1, 1, 1)
GO
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(2, 2, 1)
GO
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(3, 3, 1)
GO
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(4, 4, 1)
GO
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(5, 2, 2)
GO
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(6, 3, 2)
GO
INSERT INTO plants_users(id, plant_id, user_id)
VALUES(7, 5, 2)
Final Query:
select
users.username,
plants.name
from
users,plants,plants_users
where
users.id = plants_users.user_id and
plants.id = plants_users.plant_id
Result:
user name
john fern1
john fern2
john orchid1
john orchid2
jane fern2
jane orchid1
jane lilly1