Solved

SQL Select Portin of a table

Posted on 2014-10-10
3
108 Views
Last Modified: 2014-10-10
Hi
I am using the following SQL  code to select a hundred rows from a table called Orders. Is there a way to
do this without using the primary key [Order ID]. I want to select parts of other tables just knowing the table name

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY [Order ID]) AS RowNum FROM Orders) AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN 1 AND 100
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 49

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 40372702
You can replace 'Orders' with any table name:
SELECT TOP 100 * FROM Orders

Open in new window

0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
ID: 40372749
IF using TOP (100) then you should use an ORDER BY statement.

SELECT TOP (100) * FROM Orders ORDER BY ID
if you don't use ORDER BY " it returns the first N number of rows in an undefined order."

If you want specifically want random rows you can order by newid()

SELECT TOP (100) * FROM Orders ORDER BY NEWID()


I'm not sure what you mean by this: " I want to select parts of other tables just knowing the table name"
0
 

Author Closing Comment

by:murbro
ID: 40373074
Thanks for the help
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question