mySQL left join?

Discussion in 'Programming' started by SimThePhpCoder, Aug 29, 2008.

  1. #1
    					$result = mysql_query("SELECT SUM(`downloads`) AS total_downloads, SUM(`votes`) AS total_votes, SUM(`demos`) AS total_demos, SUM(`views`) AS total_views 
    					FROM theme_stats_by_day WHERE 1 
    					AND `day` BETWEEN $start_date AND $end_date 
    					GROUP BY `theme_id` 
    					ORDER BY total_downloads DESC
    					LIMIT $start,12") or die(mysql_error());
    Code (markup):

    how do I add a left join to get things from my "themes" table such as name, id and other things associated with the theme?
     
    SimThePhpCoder, Aug 29, 2008 IP
  2. Dman91

    Dman91 Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to give information about where to Join the table i mean both of your tables do have some common column ?
     
    Dman91, Aug 30, 2008 IP
  3. vasago

    vasago Peon

    Messages:
    95
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $result = mysql_query("SELECT SUM(`downloads`) AS total_downloads, SUM(`votes`) AS total_votes, SUM(`demos`) AS total_demos, SUM(`views`) AS total_views
    FROM theme_stats_by_day
    LEFT JOIN themes ON theme_stats_by_day.theme_id = themes.id
    WHERE 1
    AND `day` BETWEEN $start_date AND $end_date
    GROUP BY `theme_id`
    ORDER BY total_downloads DESC
    LIMIT $start,12") or die(mysql_error());

    .. for example
     
    vasago, Sep 1, 2008 IP
  4. SimThePhpCoder

    SimThePhpCoder Well-Known Member

    Messages:
    949
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #4
    tanks vasago.
     
    SimThePhpCoder, Sep 1, 2008 IP