slack Posted April 2, 2006 Share Posted April 2, 2006 Hi all,I have attempted to do this but I can't seem to get the results I need. Here is the scenario:I have two tables TABLE 1 and TABLE 2. Notice that CALL_ID in TABLE 2 is referencing CALL_ID in TABLE 1.[b]TABLE 1CALL_ID -------- NAME[/b]1 ------------------- Mike 2 ------------------- John 3 ------------------- Kelly [b]TABLE 2ID ------------ CALL_ID [/b]1 ---------------- 12 ---------------- 1 3 ----------------- 3 Info is to be displayed like below. So basically if that persons CALL_ID is in TABLE 2 then it should say YES.[b]NAME------------ ACTION[/b]Mike --------------- YESJohn --------------- NOKelly --------------- YESI know I need some sort of loop that loops through TABLE 1 and for every entry it should check to see if its CALL_ID matches a CALL_ID in TABLE 2.I know that this may be a bit to ask but could somebody please post the code for the loops to get the display I want.Thank youSlack Quote Link to comment Share on other sites More sharing options...
toplay Posted April 2, 2006 Share Posted April 2, 2006 You don't need two queries, just one. Example:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] table1.NAME, IF(table2.CALL_ID IS NULL, [color=red]'NO'[/color], [color=red]'YES'[/color]) [color=green]AS[/color] `Action`[color=green]FROM[/color] [color=orange]table1[/color] [color=green]LEFT[/color] [color=green]JOIN[/color] table2ON table1.CALL_ID [color=orange]=[/color] table2.CALL_ID [!--sql2--][/div][!--sql3--]Join tutorial/examples:[a href=\"http://www.w3schools.com/sql/sql_join.asp\" target=\"_blank\"]http://www.w3schools.com/sql/sql_join.asp[/a][a href=\"http://dev.mysql.com/doc/refman/4.1/en/control-flow-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/con...-functions.html[/a] Quote Link to comment Share on other sites More sharing options...
slack Posted April 3, 2006 Author Share Posted April 3, 2006 THANKS. Your advice has worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.