Mysql query retreving data from three table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shoaib
Forum Newbie
Posts: 5
Joined: Wed Feb 18, 2009 10:17 am

Mysql query retreving data from three table

Post by shoaib »

[Moved by moderator to Databases forum]
hi guys!!

i m stuck here a mysql query , i have three tables,category,product,speciality.

In category colum the fields are cat_id, cat_name.
In product table prod_id,prod_name,prod_desc,cat_id(FK).
In Speciality Table i have spec_id,spec_name,prod_id(FK).

The problem is i want a list view of category,prod_name,spec_name,when i use inner join i don't get the required result , like if inner join category and product table i did get the categoy and there product but when i join the speciality table it only shows those categories, which have specialites.

The query is used for two table is select * from product inner join category where category.cat_id=product.cat_id;

Some products have speciality and some have not.

can any body tell me how to do it,

Thanks
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Mysql query retreving data from three table

Post by tech603 »

In this case you may want to use an outer join. These links should help you on your way.

Php mysql join Tutorial.
http://www.tizag.com/mysqlTutorial/mysqljoins.php

Mysql Docs
http://dev.mysql.com/doc/refman/5.0/en/ ... ation.html
Post Reply