Possible Duplicate:
How can an SQL query return data from multiple tables
I have 3 table
Attribute
attr_id | attr_name
1 | oval<
2 | white
Product
product_id|product_name
1 | amazonite
2 | agate
attr_detail
attr_detail_id | attr_id | product_id
1 | 1 | 1
2 | 2 | 1
3 | 1 | 2
4 | 2 | 2
Now I want product those are oval shape and white color. How to use join.
Try this:
SQL Fiddle Demo
This will give you:
Note that: This will give you the products names that have either the
whiteorovalshapes. However, if you are looking for only those products that has both the two shapes, you have to modify your query like so:Updated SQL Fiddle Demo
This will give you:
Please read more about
JOINs. Here you can find a useful information about this:Join (SQL)From Wikipedia.
Visual Representation of SQL Joins.
Another Visual Explanation of SQL Joins.
SQL Queries for Mere Mortals(R): A Hands-On Guide to Data Manipulation in SQL, a great book for SQL Basics.
For what I did in the second query:
This is called Relational Division.