Jump to content

Combining Query Results


Kemik

Recommended Posts

Hello,

 

I have two queries which searches for any fixtures your clan (team) is in and then returns some information about the fixtures. Is there any way of combining these results and ordering them by date?

 

$query = "SELECT lc.*, cb.name as clan, cb.clan_id, ladder.name as ladder, ladder.ladder_id
FROM ladder_challenges lc
	LEFT JOIN clans cb ON lc.clan_id_b = cb.clan_id
	LEFT JOIN ladder_config ladder ON lc.ladder_id = ladder.ladder_id
WHERE lc.clan_id_a = $myclanid AND lc.accepted = 0";

$query = "SELECT lc.*, ca.name as clan, ca.clan_id, ladder.name as ladder, ladder.ladder_id
FROM ladder_challenges lc
	LEFT JOIN clans ca ON lc.clan_id_a = ca.clan_id
	LEFT JOIN ladder_config ladder ON lc.ladder_id = ladder.ladder_id
WHERE lc.clan_id_b = $myclanid AND lc.accepted = 0";

 

Thanks all.

Link to comment
https://forums.phpfreaks.com/topic/66784-combining-query-results/
Share on other sites

try a UNION

<?php

$query = "SELECT lc.*, cb.name as clan, cb.clan_id, ladder.name as ladder, ladder.ladder_id
    FROM ladder_challenges lc
	    LEFT JOIN clans cb ON lc.clan_id_b = cb.clan_id
	    LEFT JOIN ladder_config ladder ON lc.ladder_id = ladder.ladder_id
        WHERE lc.clan_id_a = $myclanid AND lc.accepted = 0
        UNION
        SELECT lc.*, ca.name as clan, ca.clan_id, ladder.name as ladder, ladder.ladder_id
    FROM ladder_challenges lc
	    LEFT JOIN clans ca ON lc.clan_id_a = ca.clan_id
	    LEFT JOIN ladder_config ladder ON lc.ladder_id = ladder.ladder_id
    WHERE lc.clan_id_b = $myclanid AND lc.accepted = 0
        ORDER BY date";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.