Subselect without condition WHERE

0

I need to do a list with sub select, and I even managed to do it using a condition, but I need to do it 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 the case I have two tables, one named "plant-order" and the other "vehicle."

InmyapplicationIneedtolistsomeoftheserviceorderdata,theyareIDOS,STATUS,PROBLEM,andthevehiclePLATEfortheID_CARRO

thePHPlistinglookssomethinglikethis

functionlistar($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 ??

    
asked by anonymous 09.05.2018 / 03:58

1 answer

2

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

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

You can see more about inner join this question

    
09.05.2018 / 04:05