SQL asked for a basic example. I can’t understand what I read in the book .. Who can help me explain why the second one is the same as the first one?

  mysql, question
Select
 id,
 name,
 cid
 From
 shbooks
 Where?
 cid=(
 Select
 cid
 From
 shbooks
 Where?
 Name=' The Glory and the Dream'
 );

I can fully understand the above, return the cid of < The Glory and the Dream >, and then use this value as a condition to match the cid of the whole table.


Select
 b1.id,
 b1.name,
 b1.cid
 From
 shbooks b1,
 shbooks b2
 Where?
 b1.cid=b2.cid
 And
 B2.name=' The Glory and the Dream';

However, if b1.cid=b2.cid, the whole table will be returned. Why can another book with the same cid as The Glory and the Dream be returned by adding b2.name=’ The Glory and the Dream’? ? ?


The answer is not long or whether the language is accurate. Just let me understand the logic. Thank you!

Original

b1.cid b1.name
 1 The Glory and the Dream
 Another book
 Dream and glory

The condition b1.cid = b2.cid (5 results obtained by filtering from 9 results) As long as you understand why it is 9 results, the whole problem should be no doubt.

b1.cid b1.name b2.cid b2.name
 1 The Glory and the Dream 1 The Glory and the Dream
 1 The Glory and the Dream 1 Dream and Glory
 Another book
 1 Dream and Glory 1 Dream and Glory
 1 Dream and Glory 1 The Glory and the Dream

Condition b2.name=’ The Glory and the Dream’
Get it

b1.cid b1.name b2.cid b2.name
 1 The Glory and the Dream 1 The Glory and the Dream
 1 Dream and Glory 1 The Glory and the Dream

I am the person who asked the question, this is what I added!
 Let me explain to you what is going on.
 In fact, logic is to treat oneself as two tables.
 And then calculate their own Cartesian set,
 Then use the second criteria to filter!