adv Posted December 9, 2011 Share Posted December 9, 2011 i have a column `full_name` and another one named `type` and i have a column `client_name` in table `data` i want to search the `full_name` with the selected `type` and match in the column `clien_name` in the table `data` and show only the ones that are in both tables Link to comment https://forums.phpfreaks.com/topic/252859-find-data-from-another-table/ Share on other sites More sharing options...
mikosiko Posted December 9, 2011 Share Posted December 9, 2011 what have you tried already?... post your code Link to comment https://forums.phpfreaks.com/topic/252859-find-data-from-another-table/#findComment-1296402 Share on other sites More sharing options...
Andy-H Posted December 9, 2011 Share Posted December 9, 2011 SELECT t.full_name FROM table t INNER JOIN data d ON ( t.full_name = d.client_name ) WHERE type = '$type' Link to comment https://forums.phpfreaks.com/topic/252859-find-data-from-another-table/#findComment-1296404 Share on other sites More sharing options...
adv Posted December 9, 2011 Author Share Posted December 9, 2011 thanks for answering what do u mean andy there SELECT t.full_name FROM table t what is "t" in ur example? and what is t. and d and here INNER JOIN data d ON data is tables `data` and d what is? Link to comment https://forums.phpfreaks.com/topic/252859-find-data-from-another-table/#findComment-1296407 Share on other sites More sharing options...
Andy-H Posted December 9, 2011 Share Posted December 9, 2011 They're just shorthand table aliases, so you say I want to reference table as t by "SELECT field FROM table t" and the t. and d. are specifying which table the field belongs to, you need to do this when you make a mysql join because say if table1 has a field named id, and table2 also has a field named id, and I select id in a query where I join the result set from each table, it doesn't know which table's id field I want to select. You could write that query like, SELECT table.fullname FROM table INNER JOIN data ON ( table.full_name = data.client_name ) WHERE table.type = '$type' Thats saying SELECT {the fullname field from the table "table" INNER JOIN {the data table} IF {full_name from table "table" is equal to client_name from table "data"} WHERE {type field from table "table" is equal to $type Link to comment https://forums.phpfreaks.com/topic/252859-find-data-from-another-table/#findComment-1296413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.