Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
easy_goer
Starting Member
21 Posts |
Posted - 2013-10-13 : 14:55:54
|
Hello. I have a portion of a table that looks like what I've listed below. This is just a small subset of the data that I'm attempting to retrieve, but this displays what the structure looks like. What I would like to do is have a script that can pull all but the top two lines. So, I want to get everything that's below the line that contains "E-Mail". Hope this makes sense.Right now, I can pull lines 3 and 4 by using the script below, but I would like also to capture the last line in my results. Any ideas?select Column1, Column2, Column3, Column4from Tablewhere Column2 in(select Column1 from Tablewhere Column1 = '22701')Column1 Column2 Column3 Column48106 NULL Top 810622701 8111 Test2 810626892 22701 Extra1 810626893 22701 Extra2 810626894 26892 ExtraSub1 8106Thank you! |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-13 : 20:27:20
|
quote: Originally posted by easy_goer Hello. I have a portion of a table that looks like what I've listed below. This is just a small subset of the data that I'm attempting to retrieve, but this displays what the structure looks like. What I would like to do is have a script that can pull all but the top two lines. So, I want to get everything that's below the line that contains "E-Mail". Hope this makes sense.Right now, I can pull lines 3 and 4 by using the script below, but I would like also to capture the last line in my results. Any ideas?select Column1, Column2, Column3, Column4from Tablewhere Column2 in(select Column1 from Tablewhere Column1 = '22701')Column1 Column2 Column3 Column48106 NULL Top 810622701 8111 Test2 810626892 22701 Extra1 810626893 22701 Extra2 810626894 26892 ExtraSub1 8106Thank you!
It is hard to deduce the rule that you want to use just from the example you posted. It could be any , or perhaps none of the following. Can you describe the rule that you want to use? I don't see a row with "e-mail" in the example dataselect Column1, Column2, Column3, Column4from Tablewhere Column1 > 26000;select TOP (3) Column1, Column2, Column3, Column4from Tableorder by Column1 desc select Column1, Column2, Column3, Column4from Tableorder by Column2 descselect Column1, Column2, Column3, Column4from Tablewhere Column3 not in ('Top','Test2'); |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-14 : 01:52:01
|
looks like this to meselect Column1, Column2, Column3, Column4from Table twhere Column1 <> Column4and not exists (select 1from Table where Column2 = t.Column1 and Column4 = t.Column4) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
easy_goer
Starting Member
21 Posts |
Posted - 2013-10-14 : 11:02:47
|
Hello. I apologize that my original post was a bit unclear. Based on the table in my original post, I am able to pull the following 26892 22701 Extra1 810626893 22701 Extra2 8106with this script..select Column1, Column2, Column3, Column4from Tablewhere Column2 in(select Column1 from Tablewhere Column1 = '22701')However, I would like to come up with a script that will display the following results..26892 22701 Extra1 810626893 22701 Extra2 810626894 26892 ExtraSub1 8106Does this make more sense? |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-14 : 12:19:21
|
quote: Originally posted by easy_goer Hello. I apologize that my original post was a bit unclear. Based on the table in my original post, I am able to pull the following 26892 22701 Extra1 810626893 22701 Extra2 8106with this script..select Column1, Column2, Column3, Column4from Tablewhere Column2 in(select Column1 from Tablewhere Column1 = '22701')However, I would like to come up with a script that will display the following results..26892 22701 Extra1 810626893 22701 Extra2 810626894 26892 ExtraSub1 8106Does this make more sense?
That you want to get the last 3 rows was clear from your original post. What is not clear to me is the rule that you used to disqualify the first two rows, and qualify the remaining 3 rows. Any of the examples I posted in my earlier post would eliminate the first two rows and give you the last 3 rows. Yet, I suspect none of them is what you are after. There is something else about the data that you are using to eliminate the first two rows. We need to program that rule - but first you have to describe what that rule is. |
|
|
|
|
|
|
|