well, first plz see my table's structure What I want: Select all from table 1 get code of the id from table2 that is declared first in data_ids of table1 i mean when it select all from table1 & printing them one by one (using while loop) it will also print code (from table2) of first declared id. so result will be like this: i think u understand now. look at the table1. in data_ids field there r some ids & first one is 2 thats why it take code (=78451) from table2 where id=2 i know its a confussing post...very messy sorry for it
try following.. SELECT table1.id, title, code FROM table1 JOIN table2 ON LEFT(data_ids, 1) = table2.id; If you want to see list from table1 even if there is no entry in table2 for the same, use LEFT JOIN.
tnx but i fount using TRIM() is better than LEFT() as u dont know the length of the id thank you again.