Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

merge data from diferent tables without relations

Posted on 2016-08-24
3
Medium Priority
?
60 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 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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

782 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