Thuong Nguyen
Thuong Nguyen

Reputation: 592

select row from 2 table where row x ( in table a) equal some value

I have two table

Table login

account_id    |    name
========================
12345         |    thuong1
12346         |    thuong2
12347         |    thuong3

Table char

account_id    |    char
========================
12345         |    name1
12345         |    name2
12345         |    name3
12345         |    name4

I want to select ...

SQL 1

SELECT account_id FORM char WHERE char='name1'

I will have result

12345

SQL 2

SELECT login.account_id, login.name, char.char WHERE login.account_id=char .account_id GROUP BY login.account_id , login.name, char.account_id, char.char HAVING login.account_id = 12345

Result

account_id | name    | char  
12345      | thuong1 | name1  
12345      | thuong1 | name2  
12345      | thuong1 | name3  

How i select it with 1 one sql query?

Upvotes: 1

Views: 242

Answers (1)

John Woo
John Woo

Reputation: 263723

SELECT  a.account_ID,
        a.name, 
        b.char
FROM    login a
        INNER JOIN char b
            ON a.account_ID = b.account_ID
WHERE   a.name='thuong1'

Upvotes: 3

Related Questions