473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

MySQL query

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
2 1620
ronverdonk
4,258 Expert 4TB
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
1,208 Expert 1GB
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

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

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: Cern | last post by:
Is it somebody out there who has made a migration from an Oracle server to an MySQL server?? The scenario is as simply: I've got a Oracle 8 server with a database with content that I want to...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
3
by: Me Alone | last post by:
Hello: I am trying to edit some C code I found in "The definitive guide to using, programming, and administering MySQL" by Paul DuBois. This C client program connects and then segfaults when...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.