Go Back   DeveloperBarn Forums > Databases > SQL Development

Sponsored Links

Discuss "top 1 problem" in the SQL Development forum.

SQL Development - Structured Query Language (SQL) is the talk of databases. Discuss topics such as joins, triggers and other advanced SQL topics.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 30th, 2008, 10:56 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default top 1 problem

hi,

I have this table called codes

Id
Codename

I want to find the top first codename value

so here is my code

strs="SELECT TOP (1) Codename * FROM Codes"

I am using access

codename is text datatype

it gives an error

The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.ect.

any idea

todd
Reply With Quote
Sponsored Links
  #2  
Old July 30th, 2008, 11:14 PM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

why do you have an asterisk (*) in there?

i would take that out and do an order by and desc.

Comments on this post
BLaaaaaaaaaarche agrees:
jmurrayhead agrees:

Last edited by Rebelle; July 30th, 2008 at 11:19 PM.
Reply With Quote
The Following User Says Thank You to Rebelle For This Useful Post:
BLaaaaaaaaaarche (July 31st, 2008)
  #3  
Old July 31st, 2008, 07:52 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

as rebelle said ... remove the asterisk
Code:
strs="SELECT TOP 1 Codename FROM Codes ORDER BY ASC"
and without using an ORDER BY clause, you could potentially get a different codename each time.
__________________
Quote of the Month:
Regret: It hurts to admit when you make mistakes - but when they're big enough, the pain only lasts a second.

Questions to Ponder:
Could it be that all those trick-or-treaters wearing sheets aren’t going as ghosts but as mattresses?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
Reply With Quote
The Following User Says Thank You to mehere For This Useful Post:
BLaaaaaaaaaarche (July 31st, 2008)
  #4  
Old July 31st, 2008, 09:48 PM
don94403's Avatar
Moderator


 
Join Date: Mar 2008
Location: San Mateo, CA, USA
Posts: 63
Thanks: 3
Thanked 8 Times in 8 Posts
Blog Entries: 2
Rep Power: 1
don94403 is on a distinguished road

Awards Showcase
PHP Microsoft Access 
Total Awards: 2

Default

Quote:
Originally Posted by todd2006 View Post
strs="SELECT TOP (1) Codename * FROM Codes"
Besides what the others have said, what is it you are trying to select? "TOP 1" makes no sense without an ORDER BY clause.
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > SQL Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 04:07 PM.



Content Relevant URLs by vBSEO 3.2.0