Join query with two tables

294
February 10, 2017, at 04:06 AM

I have this SQL query that didn't return any rows. I checked those tables which contain data so I think my query is incorrect.

)]2]1

my query is:

SELECT payment_type,with_service_total,sale_nm 
FROM `ospos_sales_payments` 
INNER JOIN ospos_sales_items ON ospos_sales_payments.sale_id = ospos_sales_items.sale_id 
WHERE 'sale_id' = '236' 
Answer 1

The error is in your syntax. You are doing WHERE 'sale_id' = '236', so you are comparing two different strings, and this condition will always evaluate to FALSE.

Your query should be written like this:

SELECT 
  payment_type,
  with_service_total,
  sale_nm 
FROM `ospos_sales_payments` 
INNER JOIN ospos_sales_items 
  ON ospos_sales_payments.sale_id = ospos_sales_items.sale_id 
WHERE sale_id = '236'

Also, if the sale_id field is numeric, you can compare to 236 also without using quotes.

Answer 2

Remove quote and add table name:

WHERE ospos_sales_payments.sale_id = '236'

or

WHERE `ospos_sales_payments`.`sale_id` = '236'
Rent Charter Buses Company
READ ALSO
herf link is not working php mysql [duplicate]

herf link is not working php mysql [duplicate]

This question already has an answer here:

383
Extract SQL Query with JSON - Codeigniter

Extract SQL Query with JSON - Codeigniter

I have a table called country_zones and theres a column called country which currently holds

371