Solved

adding other users to an existing query: looking for the most simplified answer

Posted on 2013-11-15
4
226 Views
Last Modified: 2013-11-18
select
   case profile_id when 'bob' then 'bob evans' else substring(profile_id,1,3) end,
   case sender when 'bob' then 'bob evans' else substring(sender,1,3) end,
   message_id,
   case this_user when 'bob' then 'bob evans' else substring(this_user,1,3) end


select column1 from table1

if column1='bob', write 'bob evans'

select case column1 when 'bob' then 'bob evans' else column1 end as MyColumn
from table1


How to add this new case statement to this existing query
select substring(profile_id,1,3),substring(sender,1,3),message_id, substring(this_user,1,3)

where 'bob' can be profile_id, sender, this_user

NOTE: I want 'bob evans' else three letters of column name
Do not do substring if 'bob evans'



ADDING TO THIS QUESTION:

THERE ARE 5 OTHER USERS

'susan': 'susan jones'
'abe' : 'abe thomas'
'mary': 'mary davis'
'dave'; 'dave parker'
'joe': 'joe advo'
0
Comment
Question by:rgb192
[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
  • 2
4 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 39651999
First make a table for your common people:

create table people (
  abbrev varchar(5),
  fullname varchar(14)
  );

insert people (abbrev, fullname) VALUES
('susan', 'susan jones'),
('abe', 'abe thomas'),
('mary', 'mary davis'),
('dave', 'dave parker'),
('joe', 'joe advo')

Then, the query might look like this:

select
   coalesce((select fullname from people where abbrev=profile_id),
            substring(profile_id,1,3)),
   coalesce((select fullname from people where abbrev=sender),
            substring(sender_id,1,3)),
   message_id,
   coalesce((select fullname from people where abbrev=this_user),
            substring(this_user,1,3))
0
 
LVL 24

Accepted Solution

by:
mankowitz earned 250 total points
ID: 39652006
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39653351
In database design there is the ACID concept, and the meaning can of "atomic" can be extended to the meanings for columns.  Each column should mean one thing and one thing only.  It's perfectly sensible to have the data base tables organized so that variants of the data are replicated.  I often do this with things that get misspelled a lot, like city names.  I keep both soundex() and metaphone() variants in the same row.  This lets me search for the city name as received from client input, but also search for similar-sounding rows.  If I miss on the name but match on the soundex or metaphone it lets me reply "Did you mean...?"

You might consider a design that had the three-letter search key abbreviation and the data you want to retrieve in separate columns:
 sKey   fName    fullName        responseData
'sus'  'susan'  'susan jones'   'sus'
'abe'  'abe'    'abe thomas'    'abe'
'mar'  'mary'   'mary davis'    'mar'
'bob'  'bob'    'robert evans'  'bob evans'

Open in new window

This will make your queries much easier to write, and if the data base ever grows to a large size it will scale up very smoothly.  The query would now say:
SELECT responseData FROM myTable WHERE sKey = $sKey LIMIT 1
0
 

Author Closing Comment

by:rgb192
ID: 39657034
Thanks for the sql code and the database acid tutorial
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

762 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