Iam Rsdfan
Iam Rsdfan

Reputation: 45

Error: Join in MySql, PHP

I have two tables in mysql one is quote and the fields are quote_id, status, created and submit_by. in submit_by field i am saving username of the employee and in employee table the fields are firs_name, last_name, username, password. I want to show in a php table the employee first name instead of username of the employee.

full quote table stucture

enter image description here

full employee table sructure

enter image description here

this is the code i am using but not getting any result

$sql = "SELECT q.quote_id, q.client_name, q.status, e.first_name 
        FROM `quote` AS q 
        LEFT JOIN `employee` AS e ON q.submit_by = e.username";

Upvotes: 1

Views: 92

Answers (2)

AakkiRock
AakkiRock

Reputation: 220

Use this one

$sql = "SELECT * , employee.first_name FROM quote 
LEFT JOIN employee ON quote.submit_by = employee.username ORDER BY quote.client_name";
$result = $dbLink->query($sql);

Upvotes: 1

Priyank
Priyank

Reputation: 3868

try this:

 SELECT quote.quote_id, quote.client_name, quote.status, employee.first_name FROM quote 
    LEFT JOIN employee ON quote.submit_by = employee.username ORDER BY quote.client_name;

Upvotes: 1

Related Questions