Solved

need help to join 3  mysql query in one(pure mysql query)(urgent)

Posted on 2012-04-09
6
296 Views
Last Modified: 2012-04-11
Ref: unsolved solution:http://www.experts-exchange.com/Database/MySQL/Q_27667370.html

hi,
bellow statement will give output like this

mysql> SELECT THREAD_ID, EVENT_ID, EVENT_NAME, SOURCE, TIMER_START, OBJECT_INSTANCE_BEGIN, OPERATION FROM EVENTS_WAITS_CURRENT WHERE THREAD_ID IN(SELECT LOCKED_BY_THREAD_ID FROM MUTEX_INSTANCES WHERE LOCKED_BY_THREAD_ID IS NOT NULL)\G
*************************** 1. row ***************************
            THREAD_ID: 126
             EVENT_ID: 605760540
           EVENT_NAME: wait/io/file/innodb/innodb_data_file
               SOURCE: fil0fil.c:4509
          TIMER_START: 5985772299618636
OBJECT_INSTANCE_BEGIN: 139829830175456
            OPERATION: write
1 row in set (0.44 sec)


now if i run another query ..

 desc threads;
+----------------+--------------+------+-----+---------+-------+
| Field          | Type         | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| THREAD_ID      | int(11)      | NO   |     | NULL    |       |
| PROCESSLIST_ID | int(11)      | YES  |     | NULL    |       |
| NAME           | varchar(128) | NO   |     | NULL    |       |
+----------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select processlist_id from threads where thread_id=126
    -> ;
+----------------+
| processlist_id |
+----------------+
|            109 |
+----------------+
1 row in set (0.00 sec)


now what i want is :
insteads of run 2 different query, how can i  add  2nd select statement in to first statement so that it add process_list in to the first query's output l.. . so when i execute first query , the output will be :

*************************** 1. row ***************************
            THREAD_ID: 126
             EVENT_ID: 605760540
              processlist_id:109
           EVENT_NAME: wait/io/file/innodb/innodb_data_file
               SOURCE: fil0fil.c:4509
          TIMER_START: 5985772299618636
OBJECT_INSTANCE_BEGIN: 139829830175456
            OPERATION: write



Thanks for your help..
0
Comment
Question by:fosiul01
[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
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Aegil
ID: 37826546
SELECT EVENTS_WAITS_CURRENT .THREAD_ID, threads.processlist_id, EVENTS_WAITS_CURRENT .EVENT_ID, EVENTS_WAITS_CURRENT .EVENT_NAME, EVENTS_WAITS_CURRENT .SOURCE, EVENTS_WAITS_CURRENT .TIMER_START, EVENTS_WAITS_CURRENT .OBJECT_INSTANCE_BEGIN, EVENTS_WAITS_CURRENT .OPERATION FROM EVENTS_WAITS_CURRENT, threads WHERE THREAD_ID IN(SELECT LOCKED_BY_THREAD_ID FROM MUTEX_INSTANCES WHERE LOCKED_BY_THREAD_ID IS NOT NULL) AND threads.THREAD_ID=EVENTS_WAITS_CURRENT.THREAD_ID\G

Open in new window


something like that should work.
0
 
LVL 29

Author Comment

by:fosiul01
ID: 37826560
hi but it saying

ERROR 1052 (23000): Column 'THREAD_ID' in IN/ALL/ANY subquery is ambiguous
0
 
LVL 8

Accepted Solution

by:
Aegil earned 500 total points
ID: 37826976
SELECT EVENTS_WAITS_CURRENT .THREAD_ID, threads.processlist_id, EVENTS_WAITS_CURRENT .EVENT_ID, EVENTS_WAITS_CURRENT .EVENT_NAME, EVENTS_WAITS_CURRENT .SOURCE, EVENTS_WAITS_CURRENT .TIMER_START, EVENTS_WAITS_CURRENT .OBJECT_INSTANCE_BEGIN, EVENTS_WAITS_CURRENT .OPERATION FROM EVENTS_WAITS_CURRENT, threads WHERE EVENTS_WAITS_CURRENT.THREAD_ID IN(SELECT LOCKED_BY_THREAD_ID FROM MUTEX_INSTANCES WHERE LOCKED_BY_THREAD_ID IS NOT NULL) AND threads.THREAD_ID=EVENTS_WAITS_CURRENT.THREAD_ID\G

Open in new window


Try the above revision, you just need to specify the table.field in each select where you are selecting from multiple tables.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 29

Author Comment

by:fosiul01
ID: 37827021
thats great thanks , it works..

is there any way to join those table via some other join example : left or right ???
or thats the only way i can join ??
0
 
LVL 8

Expert Comment

by:Aegil
ID: 37827078
yeah, you should be able to do left / right joins,

I guess it would be from threads left join threads on threads.THREAD_ID=EVENTS_WAITS_CURRENT.THREAD_ID
or something similar. It depends on how your database is setup.  I'm not great on the joining config though myself, if you need further help on that maybe there are some other guys with better db knowledge here .
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37827094
[ERROR 1052 (23000): Column 'THREAD_ID' in IN/ALL/ANY subquery is ambiguous
This may be solved by using the table.column AS name notation when referring to the ambiguous columns.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

734 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