Using phpMyAdmin 5.1.44 to experiment with DML commands.
I’ve been following tutorials on-line.
SELECT book.b_isbn, publisher.p_name FROM 'book', 'publisher' WHERE book.b_title='DSA'
Table 1
book
b_id(PK) b_isbn b_title p_id(FK)
-----------------------------------------
1 12345 DSA 1
2 23456 SD 1
3 34567 CSP 2
Table 2
publisher
p_id(PK) p_name
--------------------
1 Fred
2 John
Expected Results
b_isbn p_name
---------------------
12345 Fred
Actual Results
b_isbn p_name
----------------------
12345 Fred
34567 John
Any ideas?
You need to tell MySQL how to join the tables together (without which it just matches every book to every publisher) – use any one of:
add
AND publisher.p_id = book.p_idto yourWHEREclause;tell MySQL to join
ONthat condition /USINGthat column;or
use a
NATURAL JOINto have MySQL guess that’s what you want based on the column names.