You're almost there in how you worded your quesiton.

You'll need a join.
select tab1.test1, tab2.test1 from tab1 inner join tab2 on tab1.id =
tab2.id.  --> this will get all columns where hte ids match.

to get all ids that are 40, add a where clause.
select tab1.test1, tab2.test1 from tab1 inner join tab2 on tab1.id =
tab2.id where tab1.id = 40.

you may also want to look at other types of joins for other results.
http://www.mysql.com/doc/en/JOIN.html

hth
Jeff



                                                                                       
                                                 
                      Paweł Filutowski                                                 
                                                 
                      <[EMAIL PROTECTED]        To:       <[EMAIL PROTECTED]>          
                                              
                      rfam.pl>                 cc:                                     
                                                 
                                               Subject:  How to get two columns from 
different tables                                   
                      11/06/2003 07:32                                                 
                                                 
                      AM                                                               
                                                 
                                                                                       
                                                 
                                                                                       
                                                 




Hello,
I`m a newer reader.
I have problem with query.
There are two tables:

tab1:

id | test1
------------
0 | string1
1 | string2
2 | string3

and tab2:

id | test1
------------
0 | string1
1 | string2
2 | string3

I want to get columns test1 (from tab1) and test2 where id.tab1 = id.tab2
but i don`t know how compare this expresion to constant i.e.  id.tab1 =
id.tab2 = 40
Haw Can I do this ?

Regards






--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to