Two tables in the database:
01. "entries". which includes the following fields: "id", "cat_id", "dateposted", "subject", "body"
02. "categories", which includes: "id", "cat"
now this query:
"SELECT entries.*, categories.cat FROM entries, categories
WHERE entries.cat_id = categories.id
..."
(It's taken from the book Practical PHP and Mysql by Jono Bacon, chapter 4)
can somebody give me a detailed explantion of what the WHERE is doing?
it's explained in the book, but not detailed enough for me to fully understand what is going on here.
thanks
explaination needed for "WHERE" command
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: explaination needed for "WHERE" command
It is very simple, it will only find results from the two tables "entries" and "categories" where the column "cat_id" from the "entries" table matches the column "id" in the "categories" table. Basically, it will join the two tables together based on those columns.
It can be more explicitly rewritten as
It can be more explicitly rewritten as
Code: Select all
SELECT entries.*, categories.cat FROM entries
INNER JOIN categories ON entries.cat_id = categories.idRe: explaination needed for "WHERE" command
thank you! =]]