?
Solved

Trying to combine 2 Select statetments

Posted on 2009-04-13
3
Medium Priority
?
176 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

800 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