Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Understanding Basic Joins

Tags:

sql

mysql

I am struggling to understand basic MySQL joins.

Basically I've got 2 tables one with a customer first name and address id in it and another with the actual address.

Rather than just displaying the customer name and an address id I want it to display the customer name and the actual address.

My basic select statement is like this:

SELECT firstName, addressId FROM Customer

It will display something like this:

firstName   addressId
---------------------
Bob         56

Rather than than I would like to join the addressId with an actual address in another table

Like this:

firstName    address
----------------------------------
Bob          45 Somewhere street

Is there anyone who can show me the best way to achieve this?

Also can anyone recommend a good tutorial for joins?

like image 624
Luke CheerfulPlum Pace Avatar asked Aug 11 '26 01:08

Luke CheerfulPlum Pace


1 Answers

SELECT  a.name, b.address
FROM    Customer a INNER JOIN AddressList b on a.addressID = b.addressID

To learn more about joins, see the article below,

  • Visual Representation of SQL Joins
like image 148
John Woo Avatar answered Aug 13 '26 14:08

John Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!