in reply to (OT) MySQL select Question

I've actually been working on a module to allow you to mimic subselections in mysql. But alas, it's on the backburner right now.

For this particular case, you could actually just use the following:

select distinctrow table1.* from table1,table2 where table1.category=1 + or (table1.category = table2.id and table2.parent_id = 1);

Hope this helps...and works as it's untested.

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: (OT) MySQL select Question
by Anonymous Monk on Jul 26, 2003 at 23:00 UTC
    Thanks, I can't tell you how long that was taking me to work out. You got it right first time and saved me further hours of work, so thanks again!
Re: Re: (OT) MySQL select Question
by Beatnik (Parson) on Jul 26, 2003 at 22:31 UTC
    mysql doesn't do subqueries yet... You better do 2 selects and insert the data from the first into the second one.

    Greetz
    Beatnik
    ... I'm belgian but I don't play one on TV.

      Umm... I know MySQL doesn't do subselects. In the selection I posted, there aren't any subselections. The module of which I was speaking was so you could actually use SQL-92 style subselections but have them translated into multiple queries which, yes, do create temporary tables. For this particular query, however, there is no need to create a second table.

      Updated: Seemed a bit harsh. Just having a bad day :-/

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1