Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

merge data from diferent tables without relations

Posted on 2016-08-24
3
Medium Priority
?
59 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
[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
3 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 2000 total points
ID: 41769606
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
ID: 41770953
thx I found the solution by myself, instead of union i use cross join
0
 

Author Closing Comment

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

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

688 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