dadamssg Posted August 12, 2009 Share Posted August 12, 2009 ok....both these queries pull up topic_id numbers. How would i combine them to where the one combined super query, if you will, will only pull up the ones that BOTH have the same topic_id numbers? SELECT topic_id FROM Topics WHERE topic_id IN (SELECT DISTINCT a.topic_id FROM Responses a INNER JOIN ( SELECT topic_id, MAX(create_date) AS maxCreateDate FROM Responses WHERE created_by = '$userr' GROUP BY topic_id ) b ON a.topic_id = b.topic_id AND a.create_date > b.maxCreateDate) and SELECT topic_id FROM newreplies WHERE user = '$username' and viewed = '0' " Link to comment https://forums.phpfreaks.com/topic/169864-help-with-combing-two-queries/ Share on other sites More sharing options...
dadamssg Posted August 12, 2009 Author Share Posted August 12, 2009 i think thats what i want but heres my test script thats not working... <?php session_start(); include("caneck.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Couldn't connect"); $sql = "SELECT topic_id FROM Topics WHERE topic_id IN (SELECT DISTINCT a.topic_id FROM Responses a INNER JOIN ( SELECT topic_id, MAX(create_date) AS maxCreateDate FROM Responses WHERE created_by = 'admin' GROUP BY topic_id ) b ON a.topic_id = b.topic_id AND a.create_date > b.maxCreateDate)"; $result = mysqli_query($cxn,$sql) or die (mysqli_error($result)); // while there are rows to be fetched... $list = mysqli_fetch_assoc($result); $ble = "SELECT topic_id FROM newreplies WHERE user = 'admin' and viewed = '0' "; $res = mysqli_query($cxn,$ble) or die (mysqli_error($cxn)); $ult = mysqli_fetch_assoc($res); $ret = array_intersect($list, $ult); print_r($list); echo "<br>"; print_r($ult); ?> it gives me this however Warning: array_intersect() [function.array-intersect]: Argument #2 is not an array in /home//public_html/main/tester.php on line 29 Array ( [topic_id] => 33 ) why isn't my second "array"($ult) not an array? Link to comment https://forums.phpfreaks.com/topic/169864-help-with-combing-two-queries/#findComment-896156 Share on other sites More sharing options...
dadamssg Posted August 12, 2009 Author Share Posted August 12, 2009 k disregard the post above...that was accidentally posted to this thread..ooops...still have no clue about combing the queries! Link to comment https://forums.phpfreaks.com/topic/169864-help-with-combing-two-queries/#findComment-896202 Share on other sites More sharing options...
fenway Posted August 21, 2009 Share Posted August 21, 2009 You simply need to join these as derived tables. Link to comment https://forums.phpfreaks.com/topic/169864-help-with-combing-two-queries/#findComment-903177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.