php - Mysql:multiple join in one table -


i have database , inside database table joins.

my first table cardtests columns id , name only. joined in tests columns :

card1_id | card2_id | card3_id

in equal cardtests.id.

my sqlquery is

select cardtests.name    tests    join cardtests    on tests.card1_id = cardtests.id   on tests.card2_id = cardtests.id   on tests.card3_id = cardtests.id 

but problem not working wanted display names of 3 cards. how thanks.

i think want 3 joins:

select ct1.name, ct2.name, ct3.name tests t left join      cardtests ct1      on t.card1_id = ct1.id left join      cardtests ct2      on t.card2_id = ct2.id left join      cardtests ct3      on t.card3_id = ct3.id; 

the left join handles rows 1 or more of card test columns may not populated.

often, though, having multiple columns same name, distinguished number, indication should using separate table, 1 row per tests , card.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -