Join three tables

can these two queries be merged into single query?


$query=mysql_query
("SELECT 
existing_clients_invoice.inv_number, 
existing_clients_invoice.inv_date, 
existing_clients_invoice.inv_subtotal,
existing_clients_invoice.inv_tax, 
existing_clients_invoice.inv_advance,
existing_clients_invoice.inv_total,
existing_clients_invoice.inv_id, 
client_master.client_name 
FROM 
existing_clients_invoice 
INNER JOIN 
client_master 
ON 
existing_clients_invoice.client_id=client_master.client_id
WHERE 
inv_id=LAST_INSERT_ID()"); 

$detail=mysql_query
("SELECT 
inv_details.qty,
inv_details.description,
inv_details.unit_price,
inv_details.line_total,
existing_clients_invoice.inv_total
FROM 
inv_details
INNER JOIN
existing_clients_invoice
ON
inv_details.inv_number=existing_clients_invoice.inv_number
WHERE 
inv_id=LAST_INSERT_ID()");

maybe… although it would help to know what the purpose of combining them might be

what table is the inv_id column in?

how many rows does the first query return? how many rows does the second query return?

i am not sure how to do this.i just want to show the invoice data which i have got from recently submitted form.i want to open a pop-up which shows the data.the tables are:
client_master,
existing_clients_invoice,
inv_details
client master just has client name in it, invoice has all invoice details,and details table has columns which are related to invoice table.
like,qty,description,etc.they can be more than two rows.

SELECT inv.inv_number
     , inv.inv_date
     , inv.inv_subtotal
     , inv.inv_tax
     , inv.inv_advance
     , inv.inv_total
     , inv.inv_id
     , cli.client_name
     , det.qty
     , det.description
     , det.unit_price
     , det.line_total
  FROM existing_clients_invoice AS inv
INNER
  JOIN client_master AS cli
    ON cli.client_id = inv.client_id
INNER
  JOIN inv_details AS det
    ON det.inv_number = inv.inv_number
 WHERE inv.inv_id = LAST_INSERT_ID()

okey!
dats really cool!i think this will solve my prob.because nothing was fetched through database when i used two queries :slight_smile: AS is important in this regard.