Problems Selecting TOP 1

# Thread: Problems Selecting TOP 1

1. Senior Member
Join Date
Dec 1969
Posts
817

## Problems Selecting TOP 1

The below statement returns 99918 when there is a 99914,99915,99916 and 99917? Any ideas?<BR><BR><BR>SELECT TOP 1 Rep_Goals.*, Rep_Sales.* FROM (Rep_Goals INNER JOIN Rep_Sales ON Rep_Goals.Rep_Number = Rep_Sales.Rep_Number) WHERE Rep_Sales.Rep_Number &#062; 99913

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Problems Selecting TOP 1

Well, you have no order by.<BR><BR>So you haven&#039;t told it what order to use.<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
817

## RE: Problems Selecting TOP 1

How do I add order by?

4. Senior Member
Join Date
Dec 1969
Posts
11,247

## If you need to ask that question

Wha tare you doing playing with a Database?<BR><BR>ok here you go you NEED to learn SQL<BR><BR>http://www.w3schools.com/sql/default.asp

5. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## LMFAO

since when did ya get like me<BR><BR><BR>HMPH<BR><BR>

6. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## RE: Problems Selecting TOP 1

Select ColumName1, ColumName2, ... from TableName where ..... Order By ColumName1<BR><BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
817

## Son.........I am a DBA!!!

Forget it....I will figure it out myself!!!

8. Senior Member
Join Date
Dec 1969
Posts
817

## That gives an error!!!

No good

9. Senior Member
Join Date
Dec 1969
Posts
11,247

## So am I

God help us all if a DBA does not know "order by"<BR><BR>And BTW how old do you think I am ?

10. Senior Member
Join Date
Dec 1969
Posts
817

## Here is the correct syntax

SELECT TOP 1 Rep_Goals.*, Rep_Sales.* FROM (Rep_Goals INNER JOIN Rep_Sales ON Rep_Goals.Rep_Number = Rep_Sales.Rep_Number) WHERE Rep_Sales.Rep_Number &#062; 99913 order by Rep_Goals.Rep_Number<BR><BR><BR>Thanks for nothing!!!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•