I have this code:
Select p_firstname, p_email
From teacher as t inner join borrowed as b
where t.p_id = b.p_id;
It works perfectly without where clause.
Once i add it, it gives record count : 0 .
Any solutions? I uploaded a picture
I have this code:
Select p_firstname, p_email
From teacher as t inner join borrowed as b
where t.p_id = b.p_id;
It works perfectly without where clause.
Once i add it, it gives record count : 0 .
Any solutions? I uploaded a picture
Are you simply trying to INNER JOIN the two tables on p_id? If that is the case:
SELECT p_firstname, p_email FROM Teacher t
INNER JOIN Borrowed b ON t.p_id = b.p_id
If you would like to return all records from the Teacher table, even when there are null p_id in the Borrowed table, use a LEFT JOIN
instead.
If I am not mistaken since you are using an inner join, instead of using Where t.p_id = b.p_id;
you need to use ON
. For example:
SELECT p_firstname, p_email
FROM teacher as t
INNER JOIN borrowed as b
ON (t.p_id = b.p_id);
If you need more info such as name = "bob"
, then you use a WHERE
statement afterwards. Try the fixed statement I wrote and let me know if it works!
EDIT:
You can also try this if teacher
and borrowed
are two separate databases:
SELECT p_firstname, p_email
FROM teacher, borrowed
WHERE (teacher.p_id = borrowed.p_id);