x

Query does not give exact results

hi all ,

how r u ???

in My Query .

 select top 10  Post.PosTD 
 from Post inner join UsersInContact on Post.UserId=UsersInContact.UserId
 where UsersInContact.ContactID=10




if i write this query , it give me the First top 10 Post Written By Only One User !! and it should Give Me top 10 Post By different Users not only one user.

assume that this is My Table :

 PostID           UserName             PostBody
 1                User1                 Hi
 2                User2                 Hi
 3                User3                 HI
 ... so on        .... so on            .... so on


when i write above Query :

it give me the First 10 Post Written By User1 only , althougth the top 10 Post Written By Different Users From User1 to User10

this is mean there is some thing wrong with relationship Between two Tabel???

note:

if i Order My Query By Using Order By PostID desc ....it give me Exact Resluts but the query seem to too slowly

more ▼

asked Feb 29, 2012 at 05:44 PM in Default

avatar image

qamooos
91 5 7 8

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You cannot guarantee the order of data without using the ORDER BY command. So, if you need a particular set of data in your TOP 10 query, you must use ORDER BY.

If you're seeing the query running slow because of ORDER BY you might be able to create an index on the table that will help.

You can use an execution plan to understand what's happening with your query and where you might be able to apply the index.

more ▼

answered Feb 29, 2012 at 05:48 PM

avatar image

Grant Fritchey ♦♦
137k 20 44 81

thank u very much

Feb 29, 2012 at 06:06 PM qamooos
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2031
x28

asked: Feb 29, 2012 at 05:44 PM

Seen: 744 times

Last Updated: Mar 01, 2012 at 08:58 AM

Copyright 2017 Redgate Software. Privacy Policy