runrunforest — 2008-12-09T03:24:30-05:00 — #1
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 ?
flashparry — 2008-12-09T03:59:17-05:00 — #2
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.
runrunforest — 2008-12-09T05:50:13-05:00 — #3
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.
flashparry — 2008-12-09T05:54:11-05:00 — #4
runrunforest — 2008-12-11T03:40:22-05:00 — #5
what if 2 tables have no relating ?
flashparry — 2008-12-11T03:44:32-05:00 — #6
It depends on what you're trying to do with your query... can you give any more details of the tables & fields?
guido2004 — 2008-12-11T03:53:31-05:00 — #7
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.
runrunforest — 2008-12-11T04:19:41-05:00 — #8
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
guido2004 — 2008-12-11T04:51:12-05:00 — #9
You can't. Not only do the 2 tables have no relation, but the queries themselves don't have a relation either.
kailash_badu — 2008-12-11T07:23:08-05:00 — #10
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