> Jiří Němec wrote:
> 
> > hello,
> > 
> > i have got a problem with SQL select:
> > 
> > I have got a table such this:
> > 
> > id_k typ name id
> >  1   f   bla1   1
> >  2   f   bla2   1
> >  2   i   bla3   1
> >  3   z   bla4   1
> >  3   f   bla5   1
> >  4   i   bla6   1
> >  4   z   bla7   1
> >  5   z   bla8   1
> > 
> > and id = 1 and I need select these rows:
> > 
> > id_k  typ nazev id
> >  1     f   bla1  1
> >  2     f   bla2  1
> >  3     f   bla5  1
> >  4     i   bla6  1
> > 
> > so, when doesn'i exist component (id_k = component) type "f" so I
> want
> > component with type "i", but when doesn't exist type "f" noir "i"
> I
> > don't want to select row with type "z".
> > 

I don't think you can do what you want in a simple SQL statement. You
seem to want to return rows based on what is in other rows of the
same table. There may be ways to join the table to itself, but I'm
not aware of a straightforward way to do this only in SQL. In PHP,
it's probably not too tough.

Just to be sure we all understand, I assume you want the following:
-At most, one row for each id_k
-If there is a row with an 'f' in the type column, return that row.
-If there is no record with an 'f' in the type column for that id_k,
and there is a record with an 'i', return that row.
-If there is no record with an 'f', nor a record with an 'i' in the
type column, do not return a row.

Is that right?

> > jiri nemec, ICQ: 114651500
> > www.menea.cz - www stránky a aplikace
> > 
> > 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


=====
Mark Weinstock
[EMAIL PROTECTED]
***************************************
You can't demand something as a "right" unless you are willing to fight to death to 
defend everyone else's right to the same thing.
***************************************

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to