Select an identifier from one table and its value from another table to search.

I have two tables named company and customers .

The company table has 3 fields ID , company and Type as:

 ID Company Type 1 ABC Running 2 XYZ Current 

Now, again, in the customers table, I presented the value of the company and customers, but here the value of the company is presented as ID as:

 Company Customer Name 1 monty 2 sandeep 

Now I want to search for the company name in the customer table, but when I put the company name in the search field, it does not show anything, because the value of the company name is in the form of an identifier in tabe.html. How can I achieve it.

Here is my search query:

 $sql = "Select * from customers where name like '%$term%' or location like '%$term%' or company like '%$term%'"; 
+4
source share
2 answers

In JOIN in two tables:

 Select * from customers AS cust INNER JOIN companies AS comp ON cust.Company = comp.Id where comp.location like '%$term%' or comp.company like '%$term%' 
+10
source
 try this SELECT co.*, cu.* FROM company as co, customers as cu where co.company_id = cu.company_id and co.company_name = '%$term%'; 
+3
source

Source: https://habr.com/ru/post/1500118/


All Articles