arifsor Posted April 17, 2006 Share Posted April 17, 2006 Helloi have two tables Clinic, ClicksClinic====CLINIC_IDCLINIC_NAMEClicks====CLINIC_IDDATE_TIMEwhenever visitor of the website click on the clinic name name my program insert clinic_id and date_time intto the Clicks table.Issue:=====i want to display the report Clinic Name Clicks=======================abc clinic 54xyz clinic 45 [b]is this possible using only One query?[/b] Link to comment https://forums.phpfreaks.com/topic/7587-getting-record-from-two-tables/ Share on other sites More sharing options...
wildteen88 Posted April 17, 2006 Share Posted April 17, 2006 I think this should do it:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] a.*, b.* [color=green]FROM[/color] [color=orange]Clinc[/color] a, Clicks b [color=green]WHERE[/color] a.CLINIC_ID [color=orange]=[/color] b.CLINIC_ID [!--sql2--][/div][!--sql3--] Link to comment https://forums.phpfreaks.com/topic/7587-getting-record-from-two-tables/#findComment-27639 Share on other sites More sharing options...
arifsor Posted April 17, 2006 Author Share Posted April 17, 2006 [!--quoteo(post=365476:date=Apr 17 2006, 03:30 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 17 2006, 03:30 AM) [snapback]365476[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think this should do it:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] a.*, b.* [color=green]FROM[/color] [color=orange]Clinc[/color] a, Clicks b [color=green]WHERE[/color] a.CLINIC_ID [color=orange]=[/color] b.CLINIC_ID [!--sql2--][/div][!--sql3--][/quote]No this will not work.let me clear following is the schema of tablesCLINICCLINIC_ID CLINIC_NAME==================================10 Abc Clinic11 Xyz ClinicCLICKSCLICK_ID CLINIC_ID DATE_TIME====================================1 10 04-17-20062 10 04-17-20063 10 04-17-2006 4 11 04-17-2006I WANT OUT PUT LIKECLINIC_NAME CLICKS=======================Abc Clinic 3Xyz Cinic 1[b]using only one query[/b] Link to comment https://forums.phpfreaks.com/topic/7587-getting-record-from-two-tables/#findComment-27644 Share on other sites More sharing options...
wildteen88 Posted April 17, 2006 Share Posted April 17, 2006 Oh, sorry I missunderstood. My MySQL Query knowledge is little vague but I think something like thi should do it:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] a.CLINIC_ID, a.CLINIC_NAME, [color=blue]COUNT[/color](b.CLINIC_ID), b.DATE_TIME [color=green]FROM[/color] [color=orange]`CLINIC`[/color] a, `Clicks` b [color=green]WHERE[/color] a.CLINIC_ID [color=orange]=[/color] b.CLINIC_ID GROUP BY a.CLINIC_NAME [!--sql2--][/div][!--sql3--] Link to comment https://forums.phpfreaks.com/topic/7587-getting-record-from-two-tables/#findComment-27647 Share on other sites More sharing options...
arifsor Posted April 17, 2006 Author Share Posted April 17, 2006 [!--quoteo(post=365484:date=Apr 17 2006, 04:39 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 17 2006, 04:39 AM) [snapback]365484[/snapback][/div][div class=\'quotemain\'][!--quotec--]Oh, sorry I missunderstood. My MySQL Query knowledge is little vague but I think something like thi should do it:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] a.CLINIC_ID, a.CLINIC_NAME, [color=blue]COUNT[/color](b.CLINIC_ID), b.DATE_TIME [color=green]FROM[/color] [color=orange]`CLINIC`[/color] a, `Clicks` b [color=green]WHERE[/color] a.CLINIC_ID [color=orange]=[/color] b.CLINIC_ID GROUP BY a.CLINIC_NAME [!--sql2--][/div][!--sql3--][/quote]it is workingm, but showing only those clinics whihc have some clicks, if there is no click on any clinic than it should display 0 Link to comment https://forums.phpfreaks.com/topic/7587-getting-record-from-two-tables/#findComment-27648 Share on other sites More sharing options...
arifsor Posted April 17, 2006 Author Share Posted April 17, 2006 [b]anybody can solve this[/b] Link to comment https://forums.phpfreaks.com/topic/7587-getting-record-from-two-tables/#findComment-27672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.