質問

I have three table,table names are user,trade,trade_photo.Here I have attached the table.

my problem is,

I want to select the trade table_table image data.

how to select the image based in user_id? enter image description here please any one help to me?

役に立ちましたか?

解決

something like this

select * from user u,trade t, trade_photo tp where u.user_id=t.user_id and t.trade_id=tp.trade_id;

if you want to select for a particular user

select * from user u,trade t, trade_photo tp where u.user_id=some_id and u.user_id=t.user_id and t.trade_id=tp.trade_id;

他のヒント

There is no need to join user table since user_id is already in the trade table.

Whith the supplied information

user

  • user_id

trade

  • user_id
  • trade_id

trade_photo

  • image
  • trade_id

You can try something as

select 
u.user_id ,
t.image
from 
trade_photo tp
inner join trade t on t.trade_id = tp.trade_id
inner join user u on u.user_id = t.user_id 
where u.user_id  = '{some user id}'

Its always better to provide some sample data and expected output, so that a proper suggestion could be provided.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top