SELECT DISTINCT (another question)
    Eric Forget 
    forgete at cafederic.com
       
    Mon Feb 10 12:49:39 CST 2003
    
    
  
>> I have 2 tables:
>> 
>>   A           B
>>   ------      -------
>>   Name        Name
>>   ptr_b
>> 
>> 
>> I want to select all unique B which have at least 1 relation to A, ordered
>> by B.Name. So I wrote this;
>> 
>>   SELECT DISTINCT A.ptr_b, B.Name FROM A, B ORDER BY B.Name
>> 
>> With that syntax the keyword has no effect: I have duplicates. Is it the
>> syntax which is illegal or is it a bug? Is there another way of doing it?
> 
> I found it:
> 
> SELECT DISTINCT B.RecID, B.Name  FROM A, B ORDER BY B.Name
I have another question with the same tables, with these data:
A   RecID   Name        ptr_b
    -----   -------     -----
    1       NameA1      1
    2       NameA2      1
    3       NameA3      3
B   RecID   Name
    -----   -------
    1       NameB1
    2       NameB2
With this query:
    SELECT RecID, Name FROM A WHERE ptr_b = 1
I got just:
    RecID   Name
    -----   ----
    1       NameA1
Why I do not get the "1 NameA2" and how can I get it? What it is weird is
that if query:
    SELECT RecID, Name FROM A WHERE ptr_b >= 1 && ptr_b <= 1
I got what I want:
    RecID   Name
    -----   ----
    1       NameA1
    2       NameA2
Finally both
 SELECT RecID, Name FROM A WHERE ptr_b >= 1 && ptr_b <= 1 ORDER BY Name ASC
and
 SELECT RecID, Name FROM A WHERE ptr_b >= 1 && ptr_b <= 1 ORDER BY Name DESC
Gives me exactly the same result!
Éric
___________________________________________________________________
 Eric Forget                       Cafederic
 ForgetE at cafederic.com             <http://www.cafederic.com/>
 Fingerprint <86D5 38F5 E1FD 5D9C 71C3  BAA3 797E 70A4 6210 C684>
    
    
More information about the Valentina
mailing list