SELECT * FROM有两个不同的表[重复]

This question already has an answer here:

I've been fiddling with this for bit and tried a couple different ways to combine both SELECT FROM statements, but I can't get it to work where I can call on fields from two tables within the same database. It works find if I remove either one. I tried to combine them using UNION (not sure if that's the correct thing), but couldn't get it to work.

Here's what I got so far with them separated:

$id = $_POST['id'];

$edit = $db->prepare("SELECT * FROM contacts WHERE id = (?)");
$edit->bind_param('s', $id);
$edit->execute();
$edit->bind_result($id, $firstName, $lastName, $email, $phone, $category);

$categories = $db->prepare("SELECT * FROM category");
$categories->execute();
$categories->bind_result($cateid, $setcategory);

echo $firstName;

while ($categories->fetch()) {
    echo $setcategory;
}

I'm new to all of this. I'd be grateful if someone could point me in the right direction. Thanks!

</div>

if the two tables have a common field then you can do something like

"SELECT A.*, B.*
 FROM contacts AS A
 JOIN category AS B
 ON A.primary = B.foreign
 WHERE A.id = (?)"

if your two tables have a comman attribute you can use inner join to do this

select * from tableA inner join tableB 
on tableA.commanKey =tableB.commanKey on tableA.id=?  

hope this will help you.