-3

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.

this is first table(sales_items[![this is second table(sales_payment))]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' 
bouletta
  • 525
  • 9
  • 19

2 Answers2

4

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.

2

Remove quote and add table name:

WHERE ospos_sales_payments.sale_id = '236'

or

WHERE `ospos_sales_payments`.`sale_id` = '236'
Calos
  • 1,783
  • 19
  • 28