Gossamer Forum
Home : General : Databases and SQL :

Help with Query.

Quote Reply
Help with Query.
Hi All,

Starting to get chilly here in the UK, anyway on with the question in hand!

OK, i need to do the following but I havnt got a clue where to start with the query. I will do my best to write this as simple as possible.

I have 3 tables.

order_m which contains the fields order_id, user_id
order_d which contains the fields order_id, domain_name plus others, but these i dont think are relevant.
registration_m which contains user_id, username, name, address etc.

Now i want a query which will list all the domain names with the users name next to it in the users name order a-z.

From what I can tell the query has to look at the registration_m and select the user_id then query this against order_m to find the order_id then query this against order_d to find the corresponding domain name. But i havnt got a clue where to start with the actual query.

Thanks in advance.
Regards

Mark
http://www.host4.me.uk

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Help with Query. In reply to
Since it seems that there is a many to many relationship between orders (domains) and registration (users), you may have to do something like the following (to avoid duplication of domain names):

PARENT QUERY
============================
SELECT order_id, domain_name
FROM order_d

THEN ADD A WHILE LOOP IN YOUR OUTPUT:

Code:
DOMAIN NAME
while () {
$query = "SELECT rm.username FROM order_m om INNER JOIN registration_m rm ON rm.user_id = om.user_id WHERE (order_id = $orderid)";
OUTPUT OF USERNAME
}

$orderid is from the first query....

Since I assume you are using MySQL, you cannot use sub-queries, which is the most effective to produce what you want, but using nested SQL statements you can achieve the same results.
========================================
Buh Bye!

Cheers,
Me