Jump to content


Photo

Help with mysql where...


  • Please log in to reply
8 replies to this topic

#1 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 24 April 2006 - 06:45 PM

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 ;)

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 April 2006 - 07:37 PM

Something like

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 25 April 2006 - 06:15 AM

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.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 April 2006 - 09:57 AM

SELECT a.name, a.author, c.cat_name
FROM article a 
INNER JOIN categories c ON a.cat_id = c.cat_id

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 25 April 2006 - 12:28 PM

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?

#6 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 25 April 2006 - 03:33 PM

bump

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 25 April 2006 - 05:32 PM

They are table aliases, defined in the query

FROM article a
INNER JOIN categories c

It makes the query easier to read than

SELECT article.name, article.author, categories.cat_name
FROM article
INNER JOIN categories ON article.cat_id = categories.cat_id

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 26 April 2006 - 11:49 AM

Thank you!

#9 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 29 April 2006 - 03:05 PM

hmmm,how to select c.cat_name from articles as it is not in the articles table but the categories !?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users