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?

3
  • 1
    and what is the output of this?
    – John Woo
    Feb 9, 2013 at 7:01
  • is the foobar column in the tableB id of tableA?
    – sandip
    Feb 9, 2013 at 7:04
  • @JW. Example of output. tableB.foobar but it will return This is white because 1 is belong to foo in tableA
    – vzhen
    Feb 9, 2013 at 7:16

2 Answers 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
0
0

Try this query:

 select * from tableB b left join tableA a On (b.foobar=a.id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.