Estou tendo um problema com o INNER JOIN.
Quando faço uma pesquisa por uma determinada venda ele me traz todas as vendas relacionadas ao código do cliente, pois é o campo “codcliente” que associa as 03 tabelas (Cliente, Venda e ItemVenda), alem de pegar somente um valor total das vendas.
Estou publicando o endereço de acesso da página, para que os amigos possam analisar e quem sabe me dizer o que fazer para obter o resultado somente da venda pesquisada.
As vendas que estão cadastradas com o mesmo cliente são as 141, 146 e 147 todas cadastradas com o mesmo códcliente.
http://www.lccinformatica.com.br/prod_consulta_venda.php
Abaixo publico o código da pagina de pesquisa.
<div align="left" style="margin:0 0 0 10px;"><h3>Consultar Venda</h3></div>
<div align="center" style=" padding:2px; width:655px; height:auto; float:left;">
<div align="left" style=" padding:2px; width:315px; height:auto; float:left;">
<label>Entre com o código da Venda</label>
<form action="prod_consulta_venda.php" name="busca" method="post">
<input size="6" type="text" value="" name="buscar"/>
<input type="submit" name="busca" value="Buscar Venda"/>
</form>
</div>
</div>
<div align="left" style=" padding:2px; width:1000px; height:auto; border-top:solid 2px; float:left;">
<br />
<?php
include 'conexao.php';
if(isset($_POST['busca'])){
$buscar = $_POST['buscar'];
$sql_listar = mysql_query("SELECT * FROM cliente
INNER JOIN venda
ON cliente.codcliente = venda.codcliente
INNER JOIN itemvenda
ON cliente.codcliente = itemvenda.codcliente
WHERE venda.codvenda LIKE '%$buscar%'")or die(mysql_error());
$total_registros = mysql_num_rows($sql_listar);
if(mysql_num_rows($sql_listar) <= 0){
echo "<meta http-equiv='refresh' content='0; URL= prod_consulta_venda.php'>
<script language='javascript'>
window.alert('Desculpe! Nenhuma Venda foi encontrada com esse código!');
</script>";
}else{
while($res = mysql_fetch_array($sql_listar)){
$conteudotabela1 .= '<tr style="color:#090;">
<td align="center">'.$res['codvenda'].'</td>
<td align="center">'.$res['codcliente'].'</td>
<td align="center">'.$res['datavenda'].'</td>
<td align="center">'.$res['total'].'</td>
<td align="center">'.$res['codproduto'].'</td>
<td align="center">'.$res['quant'].'</td>
<td align="center">'.$res['preco'].'</td>
<td align="center">'.$res['nome'].'</td>
<td align="center">'.$res['endereco'].'</td>
<td align="center">'.$res['bairro'].'</td>
<td align="center">'.$res['cidade'].'</td>
<td align="center">'.$res['estado'].'</td>
<td align="center">'.$res['cep'].'</td>
</tr>';
}}}
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<table class="tbllista" style="width: 15%">
<thead>
<tr align="center">
<th style="width: 5%"></th>
<th style="width: 5%">
</tr>
</thead>
</table>
<table class="tbllista" style="width: 100%">
<thead>
<tr align="center">
<th align="center">Cód. Venda</th>
<th align="center">Cód. Cliente</th>
<th align="center">Data da Venda</th>
<th align="center">Total da Venda</th>
<th align="center">Cód. Produto</th>
<th align="center">Quantidade</th>
<th align="center">Preço Unitário</th>
<th align="center">Nome</th>
<th align="center">Endereço</th>
<th align="center">Bairro</th>
<th align="center">Cidade</th>
<th align="center">Estado</th>
<th align="center">Cep</th>
</tr>
</thead>
<tbody>
<?php echo $conteudotabela1; ?>
</tbody>
A minha dúvida é como fazer para que eu receba somente os dados da venda consultada referente ao código da venda pesquisada, independente que seja do mesmo cliente ou não.
Agradeço a atenção de todos, já desejando Boas Festas.