How to do inner join in mysql?

1

I have 2 tables in my bank, Categories and Automoviles. The Categories table has a PK ID_category and Name. Automobiles already has a PK ID_automoveis and the other columns that make up this table INCLUDING the FK Category_ID as you can see in the image below:

I'm starting my studies in databases with mysql but I'm having a lot of difficulties in relational and inner join models. If something is wrong I can change it too!

This bank is manipulated by a system in PHP.

    
asked by anonymous 31.05.2017 / 12:14

2 answers

4

Try this friend:

select
    *
from
    categorias c
inner join
    automoveis a
on a.ID_Categoria = c.ID_categoria
    
31.05.2017 / 12:47
2

Your database is not normalized. First, it would normalize the DB, thus creating the tables:

  • Brand;
  • Template;
  • Color;
  • Category;
  • Automobile;

After this, I would consider making the queries, where you can use different joins:

  

INNER JOIN or JOIN only: Returns records that have values   corresponding in both tables;

     

LEFT JOIN: returns all records in the table on the left and the   corresponding records from the right table;

     

RIGHT JOIN: return all records from the right table and the   Matching records from the left table;

     

FULL (OUTER) JOIN: Returns all records when there is a   match in the left or right table

    
31.05.2017 / 12:39