Solved

merge data from diferent tables without relations

Posted on 2016-08-24
3
39 Views
Last Modified: 2016-08-25
I hope you can help me with this

I have this two querys
query 1
select field1 from table1 where field1 = 'a'

Open in new window


query 2
select field2 from table where field2 = 'a'

Open in new window


I need to present to my user field1 and field2 as a one table

I was trying to use a union
select field1 from table1 where field1 = 'a'
union all
select field1 from table1 where field1 = 'a'

Open in new window


but mysql show me the result in a single column and I need it in two, for example:
-------------------------------------------------------------
|   field 1                       |       field 2                |
|-----------------------------------------------------------|
|  results of field 1      |  results of field2     |
-------------------------------------------------------------

is it possible to do it like that???
0
Comment
Question by:altariamx2003
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 500 total points
Comment Utility
Select Query1.someCommonField, Query1.field1, Query2.field2
From
(
Select field1, someCommonfield1 as "Common" from table1 where field1 ='a'
) as Query1
inner join
(
Select field2, someCommonField2 as "Common" from table2 where field2='a'
) as Query2
On Query1.Common = Query2.Common
Order By Query1.field1

Open in new window

Realise that the SQL server NEEDS to know how the information from the two fields relate to one another in order to match up the two values.
You, as a human being and familiar with the data, can match the two up.  How are you doing that?  How can you express it in clear language?
Once you can do that, you can fix the query above to meet your needs, even if the relationship is complex.
0
 

Author Comment

by:altariamx2003
Comment Utility
thx I found the solution by myself, instead of union i use cross join
0
 

Author Closing Comment

by:altariamx2003
Comment Utility
Thx anyway for your time, but I found the solution bymyself
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
Creating and Managing Databases with phpMyAdmin in cPanel.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now