Jump to content

Archived

This topic is now archived and is closed to further replies.

feri_soft

Help with mysql where...

Recommended Posts

So how to put many parameters into the where clause.For example i have 5 cat ids and i want to select all
data that matches one of the 5 categories.CAn you give me the sql code please ;)

Share this post


Link to post
Share on other sites
Something like

[code]SELECT ... whatever... FROM tablename WHERE catID IN (1,2,3,4,5)[/code]

Share this post


Link to post
Share on other sites
And one more question.I have the cat ids in the articles table,but the categories names are in other table,so how when i am listing the articles instead of the catid to list the catego ry name.How to joint the tables or...i dont know.

Share this post


Link to post
Share on other sites
[code]SELECT a.name, a.author, c.cat_name
FROM article a
INNER JOIN categories c ON a.cat_id = c.cat_id[/code]

Share this post


Link to post
Share on other sites
I understood that category and article are my tables but what are all those a and c.If i put the code exactly as is would it work or the a and c must be changed?

Share this post


Link to post
Share on other sites
They are table aliases, defined in the query

FROM article [b]a[/b]
INNER JOIN categories [b]c[/b]

It makes the query easier to read than

[code]SELECT article.name, article.author, categories.cat_name
FROM article
INNER JOIN categories ON article.cat_id = categories.cat_id[/code]

Share this post


Link to post
Share on other sites
hmmm,how to select c.cat_name from articles as it is not in the articles table but the categories !?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.