Re: RE:Please Help me!!!

From: Date: Mon, 04 Dec 2000 10:10:35 +0000
Subject: Re: RE:Please Help me!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28551@lists.php.net to get a copy of this message
On Mon, 04 Dec 2000 14:49:56 +0800, Wen Ni (wnleong@mail.tke.po.my) wrote: >Hi, >I have some problem with my SQL queries. Maybe this problem is quite >easy for you all but I'm still not familiar with PHP so I hope you >all >can help me. I need it quite urgently to solve my company program. > >I am writing PHP3 with MYSQL. I need to query multiple data from one >table to compare them with other table. > >For example I need to select data a,b,c,d from table 1 and then >compare >with data in table 2. If these data are matching with table 2, then >I >don't want to display them. I only want to display the one which are >not match. > >here is my error coding: > >$count=0; >$query1 ="select doc from table1 where doc_no='$x' and doc_rev='$y' >and >status='$o' and title_type='$b' "; >$result1 = mysql_query($query1,$db); >while($doc = mysql_fetch_row($result1)) > { > $query = "select $a,$b,$c,$d from table 2 where status=$o and a >!='$doc[0]' order $b"; > $result1 = mysql_query($query,$db); > while($data = mysql_fetch_row($result1)) > { > print "data=$data[0]<br>\n"; > } > $count++; > } > >Can you help me to correct them? I can't make only unmatched data to >display on the form because they are while looping. > >so please help me. try doing a left join: select table1.* from table1 left join table2 using (doc_no, doc_rev, status, title_type) where table2.doc_no!=table1.doc_no or table2.doc_rev!=table1.doc_rev or table2.status!=table1.status or table2.title_type!=table1.title_type that might do what you want but its hard to tell. - Mark

« previous php.general (#28551) next »