SQL-запрос для выбора из таблицы с помощью предложения WHERE для другой таблицы

Я пытаюсь запустить этот SQL-запрос в PHP:

$sql="select b.company as c, c.company, c.resellerid from billing b, customer c WHERE (b.company = c.customerid OR b.company = c.voip_account OR b.company = c.sequence) AND c.resellerid = '0' and source = 'CDR' group by b.company asc ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs)) {
$sql2="select company,extension,phone,calltype,seconds,who,customer_bill,inclusive,timestamp from billing where company='".$result["c"]."' and source='CDR' ";
$rs2=mysql_query($sql,$conn);
$result2=mysql_fetch_array($rs2);

echo $result["c"].' - '.$result2["company"].'<br>';
}

billing.company может равняться любому из следующих

customer.sequence
customer.customerid
customer.voip_account

я хочу выбрать все строки в billing стол где customer.resellerid = 0 а также:

billing.company = customer.sequence OR billing.company = customer.customerid OR billing.company = customer.voip_account

но его возвращающиеся строки, где resellerid не равно 0

0

Решение

Я не понимаю, почему есть два запроса …

SELECT DISTINCT b.company b_company
, b.extension
, b.phone
, b.calltype
, b.seconds
, b.who
, b.customer_bill
, b.inclusive,timestamp
, c.company c_company
, c.resellerid
FROM billing b
JOIN customer c
ON b.company IN(c.company,c.voip_account,c.sequence)
AND c.resellerid = 0
AND source = 'CDR'
ORDER
BY b.company;

И обратите внимание, что PHP mysql_ API давно устарел

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector