Solved

SQL Select Portin of a table

Posted on 2014-10-10
3
114 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:Murray Brown
[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 50

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 49

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:Murray Brown
ID: 40373074
Thanks for the help
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

717 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