php - mysql query from 2 tables with conditions -


i have 2 tables

orderitems

+--------+------------+------------------+---------+ | item_id| item_name | item_type | trans | +--------+------------+------------------+---------+ | 1 | devon | line_item | 0 | | 2 | 100 | coupon | 0 | | 3 | contin | line_item | 1 | +--------+------------+------------------+---------+

orderitems_data

1+--------+------------+------------------+-----------+ | id | item_id | item_key | key_val | +--------+------------+------------------+------------+ | 1 | 1 | delivery | 2015/04/03 | | 2 | 1 | attrib | pick_up | | 3 | 1 | qty | 1 | | 4 | 2 | discount | 0 | | 5 | 3 | delivery | 2015/04/15 | | 5 | 3 | attrib | doorstep | +--------+------------+------------------+------------+

i need select 'item_name' 'orderitems' 'item_type = line_item' , 'trans=0', 'key_val' 'orderitems_data' 'item_key = delivery', , 'key_val' 'item_key=attribute' same 'item_name'

then display them. struggling query, want write

 select orderitems.item_name item_name orderitems.item_type='line_item' , trans=0, orderitems_data.key_val deliverydate item_key='delivery', orderitems_data.key_val location item_key='attrib' orderitems inner join order_items_data on orderitems.item_id = orderitems_data.item_id 

but isnt right.

could point me in correct direction please?

the result i'm looking is

devon pick_up 2015/04/03 

this -

select orderitems.item_name item_name, orderitems_data.key_val deliverydate, orderitems_data.key_val location orderitems left join orderitems_data on orderitems.item_id = orderitems_data.item_id orderitems.item_type='line_item' ,      orderitems.trans=0  ,      ( orderitems_data.item_key='delivery' or orderitems_data.item_key='attrib') 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -