Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 4 of 4
  1. #1
    Platinum Lifetime Member
    SGBoise's Avatar
    Join Date
    Jan 2008
    Location
    USA
    Posts
    41
    DNF$
    275
    Bank
    0
    Total DNF$
    275
    Donate  

    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

  2. #2
    DNF Addict
    south's Avatar
    Join Date
    Dec 2006
    Location
    33143/04930
    Posts
    4,905
    DNF$
    6,764
    Bank
    0
    Total DNF$
    6,764
    Donate  
    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 good for 72 hours except running auctions

    Progeria Research | Pulmonary Fibrosis | Dammit!

  3. #3
    Platinum Lifetime Member
    SGBoise's Avatar
    Join Date
    Jan 2008
    Location
    USA
    Posts
    41
    DNF$
    275
    Bank
    0
    Total DNF$
    275
    Donate  
    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

  4. #4
    Platinum Lifetime Member
    kengreenwood's Avatar
    Join Date
    May 2006
    Location
    Tampa
    Posts
    400
    DNF$
    4,963
    Bank
    0
    Total DNF$
    4,963
    Donate  
    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'

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Domain name forum recommended by Domaining.com