Subselect without condition WHERE

Asked

Viewed 29 times

0

I need to do a list with sub select, and even managed to do it using a condition, however, I need it to occur without condition with the condition would look something like this:

SELECT *,(SELECT PLACA from veiculo WHERE ID_CARRO = "1654641106") as placa from ordem_os

In case I have two tables, one named "ordem_servico" and the other "vehicle".Tabela veiculo

Tabela OS

and in my application I need to list some data of the order of service, are they, ID_OS, STATUS, PROBLEM and the vehicle PLATE related to ID_CARRO

PHP listing looks something like this

function listar( $link )
{
    $select = "SELECT * FROM ordem_os ";
    $result = mysqli_query($link, $select);
    $linha = mysqli_fetch_assoc($result);

    if( !empty($linha) )
    {
        do
        {
        ?>
            <tr data-toggle="modal" data-target="#exampleModal">
                <td><?php echo $linha['ID_OS'] ?></td>
                <td><?php echo $linha['PLACA'] ?></td>
                <td><?php echo substr($linha['PROBLEMA'], "0","40")."..." ?></td>
                <td><?php echo $linha['STATUS'] ?></td>
            </tr>
        <?php
         }while($linha = mysqli_fetch_assoc($result) );
    }
    else
    {
    ?>
        <tr>
            <td colspan="4">
                <div class="mensagem_nenhum_registro">
                    Ops!Nenhum registro encontrado
                    <br>
                    <img src="imagens/not_found_icon.png">
                </div>
            </td>
        </tr>
    <?php
    }            
}

?>

How should be my query to get the card referring to the "ID_CARRO" that is listed??

1 answer

2


Making a join between the tables is possible, will pick up the vehicle and "join" with the service order information

Select
    *
from ordem_servico
    inner join veiculo on veiculo.id_carro = ordem_servico.id_carro

You can see more inner join in that question

  • Putz, I didn’t even remember the kkk joins thank you very much

  • We are there for that ;P, if you decided not to forget mark an answer as accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.