Forum Moderators: open

Message Too Old, No Replies

Simple query. but stuck

I am confused.. please help

         

tabish

11:03 am on Jun 13, 2008 (gmt 0)

10+ Year Member



Hi all,

I have two table in my sql, in one (we will call it table A) table i have username,profile_setting field and in another table (table B) i have username,age,prefrence,otherthing,city,name

Now.. the profile setting is saved on table A and rest of the thing is in table B

Now what i want is.. i want to list the latest profiles according to table B but it should NOT have the profile_setting!='private' (which is in table A).. i want to list 20 latest profiles from table B but it should fulfil the profile_setting!='private' condition from table A.

I need it in one query.. please help.

Regards

kjshier

5:10 pm on Jun 13, 2008 (gmt 0)

10+ Year Member



SELECT TOP 20
,b.[username]
,b.[age]
,b.[prefrence]
,b.[otherthing]
,b.[city]
,b.[name]
FROM [My_TableA] a
INNER JOIN [My_TableB] b ON a.[username]=b.[username]
WHERE a.[profile_setting] = 'private'

Finding the latest profiles is tough unless you have some means of knowing when they were inserted i.e. Date or record number.
With that you would add to the bottom of the script:

ORDER BY DATE DESC