By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

MySQL query

P: 1
Sorry to post a begginer question here... I am having difficulty with MySQL query here. do I use "join" or "sub-query" for things like this? I'm hoping that someone can show me how to write query for things like this.

I have following tables:

table: special
contains: special_id, special_name

table: keyword_2_special
contains: keyword_id, special_id

table: keyword_2_product
contains: keyword_id, product_id

table: product
contains: product_id and other things

What I would like to do is this. I get the special name from POST action and set the valiable to $special_name. From there, I want to list all the product that has same keyword_id as the special.

With my limited knowledge, I wrote multiple query to get the product_id's, I don't know how I get product_name's from those product_id's since there are multiple products in the result...

I have tried searching the solutions all over, but I guess I'm not searching with the right word...

Any help is greatly appriciated.
Jun 18 '06 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
To me I think the following query (not tested) should do it. Of course there are a hundred ways to accomplish it (with JOINs, for instance). Give it a try:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. special.special.id, special.special_name,
  3. keyword_2_special.keyword_id, keyword_2_special.special_id,
  4. keyword_2_product.keyword_id, keyword_2_product.product_id,
  5. product.product_id, product.other_things
  6. FROM
  7. special, keyword_2_special, keyword_2_product, product,
  8. WHERE
  9. special.special.id = keyword_2_special.special_id            AND
  10. keyword_2_special.keyword_id = keyword_2_product.keyword_id  AND
  11. keyword_2_product.product_id = product.product_id;
Ronald :cool:
Jul 22 '06 #2

iam_clint
Expert 100+
P: 1,208
Select * from special s
left outer join keyword_2_special k2s on s.special_id = k2s.special_id
where s.keyword_id = $special_name

i am sure this isn't what you are looking for but i didn't fully understand what your looking for here give me example of the tables like 3 lines of each table and Explain alittle better what fields you want to be joined onto what other fields.
Jul 26 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.