Please explain MySQL Joins in simple language

前端 未结 3 1652
孤街浪徒
孤街浪徒 2020-12-06 08:20

Please explain to me joins in simple language. Please do not post a web link as I need to read how a developer understand it, not an author.

3条回答
  •  温柔的废话
    2020-12-06 08:30

    I'm interpreting your question to mean joins in a very general sense, not each type of join, so if this is off the mark then I apologize:

    Basically, joins enable you to get data from multiple tables in a single query by adding columns to your result set. So if you had the following tables:

    Books   (ID, Title, AuthorID)
    Authors (ID, Name)
    

    You could get a result set that looked like this:

      Book                    |   Author
    'The Sirens of Titan'     | 'Kurt Vonnegut'
    'The Old Man and the Sea' | 'Earnest Hemingway'
    

    By joining the two tables together like so:

    select Books.Title as Book, Authors.Name as Author
    from Books
    inner join Authors on Authors.ID = Books.AuthorID
    

    An inner join is the simplest type of join; it may be difficult to understand the point of outer joins without first having a strong grasp of inner joins and their uses.

提交回复
热议问题