D
D
delongeroman2020-11-12 00:11:28
SQL
delongeroman, 2020-11-12 00:11:28

Can I do a database search?

I have a database with 3 tables.
Orders:
5fac51ea62f60365015672.png
Companies
5fac51f624a34137879697.png
Customers
5fac51fe57e6c981687696.png

Using JOIN I connect them

SELECT * FROM `orders` LEFT JOIN companies ON orders.company_id=companies.id LEFT JOIN clients on orders.client_id=clients.id WHERE companies.id=clients.company_id

The output is:
5fac52cf33426383486111.png

This will be displayed on my site and I was wondering if I could implement a search by customer number in a table that is spliced ​​via JOIN?

Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N, 2020-11-12
@delongeroman

SELECT * 
FROM `orders` 
LEFT JOIN `companies` ON `orders`.`company_id` = `companies`.`id` 
LEFT JOIN `clients` ON `orders`.`client_id` = `clients`.`id` 
WHERE `companies`.`id` = `clients`.`company_id`
AND `clients`.`phone` = '1234567890'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question