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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Alphabetic list

Author  Topic 

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2011-06-06 : 07:21:29
Hi, I've got a table with titles.
I want to create a query which results in a list of unique characters which do exist as first characters of the titles.
So if the table looks like this:

ID Title
1 Bear
2 Wolf
3 Apple
4 Beast
5 Window
6 Swallow


It would result in:
A
B
S
W

How can I do that?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-06 : 07:34:04
select distinct left(fld,1)
from tbl


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2011-06-06 : 08:00:01
That's great!!!
But now, what if I had three tables with titles, and still want to return one list?

The secret to creativity is knowing how to hide your sources. (Einstein)
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-06-06 : 08:08:54
Step 1: Normalize your database.
Step 2: ????
Step 3: Profit.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-06 : 08:10:24
select left(Title,1) from tbl1
UNION
select left(Title,1) from tbl2

and so on...

The UNION will give distinct values...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2011-06-06 : 08:53:05
Ok, that was easier then I suspected.
Thanks to you all...

The secret to creativity is knowing how to hide your sources. (Einstein)
Go to Top of Page
   

- Advertisement -