[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL JOIN when no columns are in common

Posted on 2011-03-06
8
Medium Priority
?
467 Views
Last Modified: 2012-05-11
Just wondering how to join 2 tables when no columns are in common.

Like

Table A => name, place, item
TABLE B=> type, rule , value

Now I want to join table A and B. Item in Table A has same data and datatype same as type in table B. But their column names are not same.
0
Comment
Question by:pal2k
[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
8 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 35047227
TRY UNION ALL

SELECT NAME, PLACE, ITEM
FROM TABLEA
UNION ALL
SELECT TYPE_RULE_VALUE
FROM TABLEB
0
 

Author Comment

by:pal2k
ID: 35047293
thks...

Wondering if UNION will be still good if I need to add a WHERE clause in TABLE A by column Item
0
 

Author Comment

by:pal2k
ID: 35047483
also the no of columns are not same in both tables...
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Accepted Solution

by:
NewDan526 earned 500 total points
ID: 35048735
Column names don't have to be the same when joining.  The USING clause or a "NATURAL JOIN" use the column names, but you should use the "ON" clause here.


SELECT a.*, b.*
  FROM a JOIN b
    ON (a.item = b.type)
 WHERE item = "xxx"
;
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 35048772
There should not be any issues if you include WHERE clause in TABLEA.

You can still work with UNION ALL even if number of columns in both tables are not same, provided you make sure that you list the column names AND it should have same datatypes in TABLEA and TABLEB
0
 
LVL 14

Assisted Solution

by:ajexpert
ajexpert earned 500 total points
ID: 35049057
Let me ask you the following before we comment.

1.  Is the data in TABLEA and TABLEB is same even though the column names are different?  If yes, which columns in TABLEA and TABLEB have the same data?

2.  How you exepect the output? listing all columns from TABLEA and TABLEB or just combining the records from TABLEA and TABLEB?
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 500 total points
ID: 35050314
Try CROSS JOIN.
SELECT *
  FROM Table_A, Table_B

Open in new window

0
 
LVL 5

Assisted Solution

by:jaiminpsoni
jaiminpsoni earned 500 total points
ID: 35060312
Select * from table_A a , table_B b where a.item = b.type;

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

649 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