mysql - How to paramaterize a JOIN? -


given following tables

mysql> describe customers; +-------------+-------------+------+-----+---------+----------------+ | field       | type        | null | key | default |          | +-------------+-------------+------+-----+---------+----------------+ | customer_id | int(11)     | no   | pri | null    | auto_increment | | login       | varchar(16) | no   |     | null    |                | | password    | varchar(40) | no   |     | null    |                | | name        | varchar(32) | no   | uni | null    |                | | address     | varchar(64) | no   |     | null    |                | | contact     | varchar(32) | no   |     | null    |                | +-------------+-------------+------+-----+---------+----------------+ 6 rows in set (0.02 sec)    mysql> describe orders; +-----------------+-------------+------+-----+-------------------+----------------+ | field           | type        | null | key | default           |          | +-----------------+-------------+------+-----+-------------------+----------------+ | customer_id     | int(11)     | no   | mul | null              |                | | order_id        | int(11)     | no   | pri | null              | auto_increment | | order_timestamp | timestamp   | no   |     | current_timestamp |                | | item            | varchar(16) | no   |     | null              |                | | price           | double      | no   |     | null              |                | +-----------------+-------------+------+-----+-------------------+----------------+ 5 rows in set (0.04 sec) 

i want rows of orders match parameterized query (my code pass in customer_id), plus customer name customers table.

how do that?

join 2 tables, , put condition in where clause @ end of query:

select   o.order_id,     o.order_timestamp,   o.item,   o.price,   c.name,   c.address,   c.contact orders o inner join customers c on o.customer_id = c.customer_id o.customer_id = ? 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -