I want to select some thing in this table and something else in that table, in one query.
How can I do that, what the query would be like ?
I'm assuming your tables are related in some way, e.g.
fields: id, firstName, lastName
fields: id, title, authorId
Then to return the titles and author names for all books:
SELECT b.title, a.firstName, a.lastName
FROM authors a, books b
WHERE b.authorId = a.id
You can also do this with JOIN, but the above is perhaps more obvious.
I have looked over the internet for quite an example, I found something simmilar to yours, but could not comprehend the a. b. thing and how the whole thing connects each other.
Through your example above, I am clear now, thank you very much.
what if 2 tables have no relating ?
It depends on what you're trying to do with your query... can you give any more details of the tables & fields?
Like flashparry said, combining two tables together in a query is called a join, and there are several types:
If there's no relation between the two tables you want to join, the result will be that all rows of the first table will be combined with all the rows of the second query.
table1 : listing
fields: id, title, price, detail, category
fields: abbreviation, meaning
$query1 = "SELECT
WHERE id = $number";
$query2 = "SELECT meaning
WHERE category = abbreviation";
I want to combine two queries into one
You can't. Not only do the 2 tables have no relation, but the queries themselves don't have a relation either.
It's hard to get the feel of your table structure but I would guess that this is what you are looking for:
SELECT id, title, price, detail, category, meaning
FROM listing l LEFT JOIN category_dictionary c ON l.category = c.abbreviation
This topic is now archived. It is frozen and cannot be changed in any way.