I am Using PHP, MYSQL. I have two tables
Table posts
with following fields
id,
title,
body,
cat_id
Table categories
with following fields
cat_id,
cat_name
Suppose, I have Following Data in posts
table
id = 1
title = "This is Test Post"
body = "This is the Body of Test Pots"
cat_id = 3
and in categories
table
cat_id = 3
cat_name = "Mobiles"
If I Use the Following SQL Statement
"SELECT * FROM posts WHERE id=1";
It will give me following output
id = 1
title = "This is Test Post"
body = "This is the Body of Test Pots"
cat_id = 3
But I Want the Following Output
id = 1
title = "This is Test Post"
body = "This is the Body of Test Pots"
cat_id = Mobiles
How can I get the above mentioned output.
Note: I know some kind of JOIN
is used in this kind of situation, But I don't know how to use it. One More thing, Is it possible to get my desired output without using any JOIN
, because I heard that JOINs
Effect the Efficiency. If JOIN
is necessary Please tell me the most efficient Way to get my desired output.