[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL - Join to columns as one

Posted on 2011-09-16
7
Medium Priority
?
384 Views
Last Modified: 2012-05-12
My current SQL statement is this:
SELECT DISTINCT home_nation, company_nation
FROM jos_users

which returns to me two columns with a listing of countries:

What I want to do is only have my SQL statement return one column of unique columns. So for example:

current return:

home_nation        company_nation
Australia
Canada
                              Canada
                              Bermuda
United Kingdom
                              Australia




Return I want:

unique_nation
Australia
Canada
Canada
Bermuda
United Kingdom
Australia


Thanks for any help!

0
Comment
Question by:elliottbenzle
[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
7 Comments
 
LVL 5

Expert Comment

by:magento
ID: 36549842

Try this.

    SELECT home_nation + ' ' + company_nation AS unique_nation
    FROM jos_user

Open in new window

0
 
LVL 21

Expert Comment

by:JestersGrind
ID: 36549890
If there is always one entry in one of the two columns, you could do something like this.

SELECT CASE WHEN home_nation = '' THEN company_nation ELSE home_nation END AS unique_nation
FROM jos_user

Greg

0
 
LVL 60

Expert Comment

by:HainKurt
ID: 36549962
try:

select distinct country from (
  SELECT DISTINCT home_nation Country FROM jos_users
  UNION
  SELECT DISTINCT company_nation FROM jos_users
)
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 60

Expert Comment

by:HainKurt
ID: 36549978
What I want to do is only have my SQL statement return one column of unique columns

and

Return I want:

unique_nation
Australia
Canada
Canada
Bermuda
United Kingdom
Australia

contradicts... you should say


Return I want:

unique_nation
Australia
Canada
Bermuda
United Kingdom
Australia

which I posted above...
0
 
LVL 5

Accepted Solution

by:
magento earned 2000 total points
ID: 36549983
Tested the below solution.

select concat(home_nation,company_nation) uniq from jos_users
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36550046
or, if its really "NULL" in either column, you could use COALESCE(home_nation, company_nation) ...
0
 
LVL 4

Author Closing Comment

by:elliottbenzle
ID: 36550209
Thanks, that did the trick.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 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