This is why I love FLOSS

<Lakario> i need a hand with a query. i have two tables- one containing questions and one containing answers. i need to perform a select that will get all of the questions and, if there is an answer, the answers joined to them. Multiple answers can exist to the same question and they are grouped by a ClaimId (so 'WHERE ClaimId = 1415' or whatever). How can I achieve this?
<CorticalStack> !m Lakario join
<the_wench> Lakario see http://dev.mysql.com/doc/refman/5.1/en/join.html
<CorticalStack> Lakario: left join, in fact join
<Lakario> i know join... but the WHERE ClaimID is the problem
<Lakario> because it's going to return nothing if there isn't an answer in the answers table
<CorticalStack> SELECT `t1`.`foo`, `t2`.`bar` FROM `table_1` AS `t1` INNER JOIN `table_2` AS `t2` ON `t1`.`uid` = `t2`.`uid` WHERE `t2`.`feh` = 'somevalue';
<CorticalStack> Lakario: adapt that example?
<Lakario> ya that is what i was doing. Nothing returns
<CorticalStack> Lakario: change the inner join to a left join
<Lakario> also tried that :\
<Lakario> the where clause is eliminating the results from the first table so nothing gets returned
<CorticalStack> Lakario: you could try pastebinning the table structres and the query you've tried and someone might want to write it for you.
<Xgc> Lakario: That's because you have join criteria in the WHERE clause.
<Xgc> Lakario: Let's finish the problem here, not #sql.
<Lakario> k
<Xgc> Lakario: LEFT JOIN ... AND t2.claim_id = 123
<Lakario> okay let's see w
<Xgc> Lakario: The claim_id is part of the join criteria and goes in the ON clause.
<Xgc> Lakario: LEFT JOIN t2 ON t1.blah = t2.blah AND t2.claim_id = 123
<Lakario> i'm using access and it doesn't like that syntax :(
<Xgc> Lakario: Why were you asking here?
<Xgc> Lakario: Access does handle outer joins.  You'll just need to look into how access does it.
<Lakario> because there is no access channel :/
<thumbs> Lakario: call Microsoft for support?

Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.