Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trying to combine 2 Select statetments

Posted on 2009-04-13
3
Medium Priority
?
179 Views
Last Modified: 2012-05-06
SELECT     TOP (1) F1
FROM         WordList
WHERE     (F1 > '')
ORDER BY NEWID()


SELECT     TOP (1) F2
FROM         WordList
WHERE     (F2 > '')
ORDER BY NEWID()

I want to take both of those select statements and combine them so that the results are two colums with one row.  
0
Comment
Question by:arthurh88
[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 39

Assisted Solution

by:appari
appari earned 600 total points
ID: 24134238
with A as (SELECT     TOP (1) F1
FROM         WordList
WHERE     (F1 > '')
ORDER BY NEWID()), B AS (
SELECT     TOP (1) F2
FROM         WordList
WHERE     (F2 > '')
ORDER BY NEWID()
)

select * from A,B
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 600 total points
ID: 24134279
In a simple manner:

SELECT (SELECT     TOP (1) F1 FROM  WordList WHERE     (F1 > '') ORDER BY NEWID()) F1,
(SELECT     TOP (1) F2 FROM WordList WHERE (F2 > '') ORDER BY NEWID()) F2
0
 
LVL 15

Accepted Solution

by:
rob_farley earned 800 total points
ID: 24134536
Yeah, go for the second one.

But... if your WordList is a large table, ordering by newid() is potentially very expensive. You're generating a new guid for each row, and then going through that list looking for the smallest random value.

It might be better to consider generating a single random number and then finding that row.

Rob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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