Reply to Re: Is it a complex sql query?

Your name:

Reply:


Posted by John Bell on 01/15/06 11:59

Hi

Check out http://www.aspfaq.com/etiquette.asp?id=5006 on how to post DDL and
sample data in a usable form

You can use something like:
SELECT TOP 4 t1.OrderID
FROM TABLE1 t1
WHERE exists (SELECT * FROM TABLE2 t2
WHERE @UserId=T2.UserId
AND T1.OrderId = T2.OrderId )

Or (better!)

SELECT TOP 4 t1.OrderID
FROM TABLE1 t1
JOIN TABLE2 t2 ON T1.OrderId = T2.OrderId AND @UserId=T2.UserId

Check out the topics "Using Joins" and "Join Fundamentals" in books online

John

<stockblaster@gmail.com> wrote in message
news:1137312110.273304.240990@g47g2000cwa.googlegroups.com...
> Another example..
>
> if i have in TABLE1:
> OrderID
> 1
> 2
> 3
> 4
>
>
> TABLE2:
> OrderID UserId
> 1 1001
> 2 1002
> 3 1002
>
>
> I want it to return only "2" and "3" if the INPUT Parameter of @UserID
> is 1002
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация