March 25, 2012

query the two table for draw in one

Question by geronimo76

Here are my tables in mysql:

        ----------------1-------------------------  
        +---------------------------+----------+
        | email                     | attempts |
        +---------------------------+----------+
        | email1@gmail.com          |       70 |
        | email2@me.com             |        1 |
        | email3@hotmail.com        |        1 |
        | email4@gmail.com          |      115 |
        +---------------------------+----------+
       ---------------2------------------------
        +----------+---------------------------+
        | accesses | email                     |
        +----------+---------------------------+
        |       24 | email1@gmail.com          |
        |        0 | email2@me.com             |
        |        0 | email3@hotmail.com        |
        |       90 | email4@gmail.com          |
        +----------+---------------------------+

query the two table for draw in one

Email   Accesses    Attempts
email1    24            70
email2     0             1
email3     0             1
email4    90           115

it is the sql:

  1. first -> select accesses, email from user;
  2. second -> select email,count(*) as intentos from userstats where intento =1 group by email;

how do I do this?
I need a query to do draw. thank’s in advance..

Answer by IT ppl

SELECT table1.email as Email, 
    table2.accesses as Acesses, 
    table1.attempts as Attempts
from table1 
INNER JOIN table2 
on table1.email = table2.email

Answer by Starx

You can use INNER JOIN to do this

SELECT 
    t1.email, t1.accesses , t2.attempts 
FROM table1 t1
INNER JOIN 
    table2 t2 ON
        t2.email = t1.email;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!