By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tbGenres (
id INT PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE tbBooks (
id INT PRIMARY KEY,
title VARCHAR(255),
genreId INT
);
INSERT INTO tbGenres (id, name) VALUES
(1, 'Action'),
(4, 'Comedy');
INSERT INTO tbBooks (id, title, genreId) VALUES
(1, 'title1', 4),
(2, 'title2', 4),
(3, 'title3', 2);
Records: 2 Duplicates: 0 Warnings: 0
Records: 3 Duplicates: 0 Warnings: 0
SELECT a.*, b.name
FROM tbBooks AS a
INNER JOIN tbGenres AS b ON a.genreId = b.id
WHERE a.genreId = 4;
id | title | genreId | name |
---|---|---|---|
1 | title1 | 4 | Comedy |
2 | title2 | 4 | Comedy |