試試這個:
SELECT c.cat_name FROM post as p
LEFT JOIN cat_list AS c
ON c.cat_id = p.cat_id
WHERE p.post_id = "3"
的樣本數據:
CREATE TABLE cat_list(
cat_id int auto_increment primary key,
cat_name varchar(30)
);
CREATE TABLE post (
post_id int auto_increment primary key,
cat_id int,
post varchar(30)
);
INSERT INTO cat_list (cat_name)
VALUES ("cat1"),("cat2"), ("cat3"),("cat4"),("cat5"),("cat6"),("cat7"),("cat8");
INSERT INTO post (cat_id, post)
VALUES (1,"jnkljlkajlkjaoiuweiuoi"), (1,"wuoieuoiuoidudjhkj"), (2,"eiuuqueiuriewuqyiuu"), (8,"vzbvbxvnbxmnbmn nmncmn");
SQL FIDDLE DEMO
更改後的ID選擇類別。
是你的問題解決? –