Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Table Joins in PHPmyAdmin

I have 2 Tables in phpmyadmin that need joining

tracklisting is my one and catelogue is the other, and are saved as innodb

They both have a column CAT.NO and would like it to be joined on this column. In catelogue it is the primary and in tracklisting it's indexed

catelogue is my parent and tracklisting would be the child as it doesn't have info for every record in catelogue. I believe this would be correct unless I'm wrong

How do I do this so that when I query on a column in tracklisting it only brings up the matches for 'catelogue' because I want to know what album it's on and not my entire 60000+ catelogue

Can this be done with phpmyadmin's interface or is this a sql statement

Many thanks

EDIT:

This was the code that worked

SELECT *
FROM tracklisting
INNER JOIN catelogue ON catelogue.`CAT NO.` = tracklisting.`TRACKLISTING CAT NO.`
WHERE tracklisting.`ARTIST` LIKE 'placebo'

Thanks to everyone that helped out

like image 647
Mark Avatar asked Dec 31 '11 10:12

Mark


People also ask

How do you join tables in a database?

The join is done by the JOIN operator. In the FROM clause, the name of the first table ( product ) is followed by a JOIN keyword then by the name of the second table ( category ). This is then followed by the keyword ON and by the condition for joining the rows from the different tables.

How do you join tables in MySQL?

To join tables, you use the cross join, inner join, left join, or right join clause. The join clause is used in the SELECT statement appeared after the FROM clause. Note that MySQL hasn't supported the FULL OUTER JOIN yet.


2 Answers

I dont know if this can be done with the interface, but with sql

SELECT * 
FROM 
  tracklisting t 
  INNER JOIN catelouge c on c.catno=t.catno 
WHERE t.id = 1
like image 110
Starx Avatar answered Sep 30 '22 19:09

Starx


You can query with a LEFT JOIN:

SELECT * FROM tracklisting LEFT JOIN catelogue ON tracklisting.`CAT.NO` = catelogue.`CAT.NO` WHERE tracklisting.`<id-field>` = <id-value>`

http://dev.mysql.com/doc/refman/5.0/en/join.html

like image 27
Ben Lee Avatar answered Sep 30 '22 20:09

Ben Lee