Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write the sql command with two tables?

Tags:

sql

mysql

table **salesrule_coupon**: fileds as the following:

           coupon_id   code

             1        Registered_send_5   
             2         test

table:salesrule_coupon_usage fileds as the following:

    coupon_id  customer_id   times_used

    1               1          1
    1  
   ...              14 ...       1..

now, i want to select out times_used where the code =Registered_send_5 where customer_id=$id. how to write the sql command? thank u.

the following is my but it not work.

$sql = "SELECT times_used FORM salesrule_coupon_usage as a 
       left join  salesrule_coupon as b on a.coupon_id  = b.coupon_id   
       where b.code = 'Registered_send_5' and   customer_id=".'$id.";

when i put

  SELECT times_used FORM salesrule_coupon_usage as a 
           left join  salesrule_coupon as b on a.coupon_id  = b.coupon_id   
           where b.code = 'Registered_send_5' and   customer_id=1

in phpmyadmin. it shows

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'salesrule_coupon_usage as a left join salesrule_coupon as b on a.co' at line 1

like image 327
downa1234 Avatar asked Dec 12 '22 22:12

downa1234


1 Answers

Why do you have the ' in from of the $id?

It should be FROM and not FORM

like image 76
nja Avatar answered Dec 23 '22 18:12

nja