DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
HomeRegisterMembershipsGetting StartedDomain Tools Domain EbooksSEO Software Domain Resellers Advertise

Go Back   DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars > Content Development > Website Development and Design Discussion > Coding/Programming/Languages
Register Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 08-26-2009, 06:50 PM   #1 (permalink)
Platinum Lifetime Member
 
SGBoise's Avatar
 
Last Online: 09-28-2009 02:11 AM
iTrader: (1)
Join Date: Jan 2008
Posts: 38
DNF$: 60
Location: USA


Problem with JOIN on multiple columns

Hi everyone,
I'm having a lot problems trying to join tables. I hope some on smart can help me.
I want to join two tables that have 2 columns on both tables to uniquely identify a record. Right now I'm using this command for the join.
Code:
SELECT DISTINCT files.*
FROM files
JOIN transactions n1 ON n1.product_id = files.product_id
JOIN transactions n2 ON n2.script_id = files.script_id
WHERE transactions.order_number = '123456';
It's still returning rows in the files table where the script_id doesn't my match product_id and script_id in the transactions table.
For example:
The product_id is 10 and script_id is 20 for order number 123456.
It will return two records 2 records.
Record 1:
product_id = 10
script_id = 20

Record 2
product_id = 10
script_id = 21

The product_id will match but script_id doesn't match. I think it's the way I have the join in my command.
I tried left, right, inner joins and joining using the where clause but nothing seem to help. I tried kicking my computer and that didn't help either.
I'm sure this is something simple but it's driving me crazy.
__________________
Video Script - The ultimate media site script
AutoVideoScript com - Run your own youtube sharing site
SGBoise is offline   Reply With Quote
Sponsored Ads
Old 08-26-2009, 07:32 PM   #2 (permalink)
DNF Addict
 
south's Avatar
 
Name: Scott
Last Online: Today 05:12 PM
iTrader: (137)
Join Date: Dec 2006
Posts: 3,132
DNF$: 2,659
Location: 33143/04930
Country:


Not a master at this stuff, but try something like this:

(I was working on an oscommerce site last weekend)

<?php

$query = "SELECT products_description.products_name, products_attributes.options_values_price ".
"FROM products_description LEFT JOIN products_attributes ".
"ON products_description.products_id = products_attributes.products_id";

$result = mysql_query($query) or die(mysql_error());

// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){

?>

////////-Then you can echo the rows like so:
<? echo $row['products_name']; ?>


//////--OR, if you want to do te select distinct.

<?
$query = "SELECT DISTINCT (a.products_attributes_id), a.products_id, a.options_id, a.options_values_id, a.options_values_price, a.price_prefix
FROM products_attributes a
WHERE a.products_attributes_id = a.products_attributes_id
AND a.products_id = a.products_id
AND a.options_values_id = a.options_values_id
AND a.options_values_price = a.options_values_price
AND a.price_prefix = a.price_prefix
limit $offset, $limit";

$result = mysql_query($query);
if(!$result){
print "Database access error: abnormal termination<BR>$query<BR>".mysql_error();
exit;
}
$num_products = mysql_num_rows($result);
$i = 0;
$bgcolor = "#FFFFFF";
while($i < $num_products){

if($bgcolor == "#FFFFFF"){
$bgcolor = "#EEEEEE";
}else{
$bgcolor = "#FFFFFF";
}

$products = mysql_result($result,$i,"products_id");
$options_values_price = mysql_result($result,$i,"options_values_price");
$options_values_id = mysql_result($result,$i,"options_values_id");


$namefind = mysql_query("SELECT products_name FROM products_description WHERE products_id = '$products'");
$name= mysql_result($namefind,0);

$sizefind = mysql_query("SELECT products_options_values_name FROM products_options_values WHERE products_options_values_id = '$options_values_id'");
$size = mysql_result($sizefind,0);

?>


//////////////---- good luck!
__________________
All offers valid for 72 hours except running auctions.

SJCParking.com | SFOOffsiteParking.com | LaGuardiaParking.net
south is offline   Reply With Quote
Old 08-26-2009, 11:53 PM   #3 (permalink)
Platinum Lifetime Member
 
SGBoise's Avatar
 
Last Online: 09-28-2009 02:11 AM
iTrader: (1)
Join Date: Jan 2008
Posts: 38
DNF$: 60
Location: USA


Thanks South. It looks like that should work. I'll give it a try.
__________________
Video Script - The ultimate media site script
AutoVideoScript com - Run your own youtube sharing site
SGBoise is offline   Reply With Quote
Old 08-27-2009, 07:51 AM   #4 (permalink)
Platinum Lifetime Member
 
kengreenwood's Avatar
 
Name: That shouldn't be too hard to figure out...
Last Online: 10-29-2009 08:46 AM
iTrader: (2)
Join Date: May 2006
Posts: 377
DNF$: 4,437
Location: Tampa
Country:


It's actually much simpler than that. And you don't need the JOIN syntax. Use this:

select distinct files.*
from files a, transactions b
where a.product_id = b.product_id
and a.script_id = b.script_id
and b.order_number = '123456'
__________________
KJG
OneWorldMedia, ZFBot
kengreenwood is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:48 PM.
Copyright @2001-2009 DNForum.com