I have 2 different mysql tables.. and I want to get data from both of them through only one query.. I know it can be done using joins.. but dont know how... can anyone help me?
You can search the internet for some hand tutorials on joining tables. I would recommend this as you will learn how to do it, not just copying and pasting code. http://www.google.com/search?q=mysql+table+joins I think this is the article where I first learned how to do joins: http://www.devshed.com/c/a/MySQL/MySQL-Table-Joins/ If you would like us to help we'll need to know your structure of your tables and what you need them joined on. -the mole
Two table must have some thing to join, for example, one table is categories have the key name cat_id, other is posts which also have cat_id to specify which category it belongs to. Now the query is something like this "
remember that there are multiple types of joins. When there is a normal join, it only returns data if there are matching rows. When using left join foo; then it will show the other table and include the rows with no matching results in the 2nd db.
It depends what you want the join to do, give us a clue. If you just want results from both, one after the other then id use 'UNION' to combine results from both tables. Like themole said, a 2 second search on google will reveal all!