troubles with inner join

I've got tables

Manga
idmanga idgenre idauthor title

Author
idauthor name surname

Genre
idgenre genre

I want to create table with fields title,genre,name,surname

select * from Manga
      inner join Author on Manga.idauthor=Author.idauthor
      inner join Genre on Manga.idgenre=Genre.idgenre

With such query I've got all columns from all table. How to exclude not needed columns?

Upvotes: 0

Views: 91

Answers (3)

ninesided
ninesided

Reputation: 23263

Instead of writing SELECT * just list the columns that you want. It also helps to give your tables aliases:

select m.title, g.genre, a.name, a.surname 
from Manga m
inner join Author a on m.idauthor=a.idauthor
inner join Genre  g on m.idgenre=g.idgenre

Upvotes: 5

sll
sll

Reputation: 62484

Use table aliases to specify from which table you need a specific column:

SELECT m.title, g.genre, a.name, a.surname
FROM Manga m
INNER JOIN Author a on m.idauthor = a.idauthor
INNER JOIN Genre g on m.idgenre = g.idgenre

Upvotes: 2

Péter Török
Péter Török

Reputation: 116256

You can't exclude unneeded columns, only include needed columns:

select Manga.title, Genre.genre, Author.name, Author.surname from Manga
      inner join Author on Manga.idauthor=Author.idauthor
      inner join Genre on Manga.idgenre=Genre.idgenre

Upvotes: 1

Related Questions