0
This is my code that makes a list of tables
<?php
$consulta = mysql_query("SELECT * FROM mesas INNER JOIN pedidos WHERE pedidos.mesa = mesas.id and conta = 0");
if (mysql_num_rows($consulta)==true) {
while($lnmesas = mysql_fetch_array($consulta)){
?>
I launch a request into the database and it inserts it with the name, size, value, produced = 0, account = 0, and the table number ai type I did that Ner Join there because I just want it to display the table containing a record in the database that the table column is = to the table number in the table tables...
But there for example I launch two orders with table number 20 then he shows me twice table 20 if I place 4 orders at table 15 he shows me four times at table 15, and I wanted him to show only one of each.
I created the SQL Fiddle to improve the explanation of the problem.
Tried using JOIN or LEFT JOIN?
– Sr. André Baill
There is also an error, you need to put AND tables.account = 0
– Sr. André Baill
use the clause
GROUP BY
– Pedro Sanção
Use distinct.....
– EduardoFernandes
Can you give me an example of this DISTINCT based on my code?
– Alfredo Lima
@Sanction how I can use GROUP BY to solve my problem?
– Alfredo Lima
In this case he will even rethink, as a table may have more than one request. In your example, if table 15 has four orders, it’s showing every order on this table, isn’t it correct? I don’t know if that’s what you want, but here is an example using GROUP BY.
– Randrade
worked exactly the way I needed, thank you very much..
– Alfredo Lima