select inner join problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Irlan agous

    #1

    select inner join problem

    Hello
    i have t tables reactie and form and this query

    $sql = "select reactie.persid, form.oproep,for m.foto,form.id from
    reactie,form
    INNER JOIN reactie ON (reactie.persid = form.id) group by reactie.persid
    order by reactie.persid DESC LIMIT 0,5";

    $result = mysql_query($sq l);

    Why i always get the error message invalid result resource? I want to group
    the persid and order them DESC. But i cant get it to work can someone please
    help?

    reactie

    logid persid
    1 2
    3 2
    4 3

    form

    id oproep foto
    2 bla blabla
    3 frt hadiha


  • Ewoud Dronkert

    #2
    Re: select inner join problem

    On Sun, 1 May 2005 20:44:42 +0200, Irlan agous wrote:[color=blue]
    > $sql = "select reactie.persid, form.oproep,for m.foto,form.id from
    > reactie,form INNER JOIN reactie ON (reactie.persid = form.id)
    >
    > Why i always get the error message[/color]

    Remove first 'reactie', or replace 'inner join reactie on r.id=f.id' by
    'where r.id=f.id'. See http://dev.mysql.com/doc/mysql/en/join.html


    --
    Firefox Web Browser - Rediscover the web - http://getffox.com/
    Thunderbird E-mail and Newsgroups - http://gettbird.com/

    Comment

    • Tim Roberts

      #3
      Re: select inner join problem

      "Irlan agous" <irlan345@msn.c om> wrote:
      [color=blue]
      >Hello
      >i have t tables reactie and form and this query
      >
      >$sql = "select reactie.persid, form.oproep,for m.foto,form.id from
      >reactie,form
      > INNER JOIN reactie ON (reactie.persid = form.id) group by reactie.persid
      >order by reactie.persid DESC LIMIT 0,5";
      >
      > $result = mysql_query($sq l);
      >
      >Why i always get the error message invalid result resource? I want to group
      >the persid and order them DESC. But i cant get it to work can someone please
      >help?
      >
      >reactie
      >
      >logid persid
      >1 2
      >3 2
      >4 3
      >
      >form
      >
      >id oproep foto
      >2 bla blabla
      >3 frt hadiha[/color]

      In addition to the other advice about removing the first "reactie", which
      was correct, you also have some confusion about the purpoose of GROUP BY.
      GROUP BY is used when you want to use the so-called "aggregate" functions,
      like SUM or COUNT. If you aren't using SUM or COUNT (or another aggregate
      function), then you don't need GROUP BY (and, in fact, CANNOT use GROUP
      BY):

      SELECT reactie.persid, form.oproep,for m.foto
      FROM reactie INNER JOIN form ON (reactie.persid = form.id)
      ORDER BY reactie.persid DESC
      LIMIT 0,5;

      Note that, since reactie.persid == form.id, there is no point in including
      both fields in the SELECT.
      --
      - Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      Working...