1

I hope I can make it clear here.

I have a tableA

id foo             bar
1  This is white   This is black

And I have another tableB, which foobar is a boolean. 1 for foo, 0 for bar in tableA

id foobar
1  1

Then how can I link to the tableA foo and bar columns when I query tableB foobar column to list out which data 1 is belongs to?

This is can be done in mysql or php?

4

2 回答 2

1
SELECT  a.*, IF(a.foobar = 1, b.foo, b.bar) result
FROM    tableB a
        LEFT JOIN tableA b
            ON a.id = b.id
于 2013-02-09T06:59:14.367 回答
0

试试这个查询:

 select * from tableB b left join tableA a On (b.foobar=a.id)
于 2013-02-09T07:18:50.980 回答