billli Posted June 3, 2008 Share Posted June 3, 2008 Hi: question 1: suppose that I have the following table: table1 with the columns: id name age email address company ... and 20 other fields. and i need to select the data from this table, but say i only need 5, which one would be faster? SELECT * FROM table1 or SELECT id, name, age, address, company FROM table1 same situation, but what if i need to select only certain fields from multi tables that are joined together? question 2: $query="SELECT * FROM table1" $result=mysql_result($query); while($data=mysql_fetch_array($result,MYSQL_ASSOC)){ // If I add MYSQL_ASSOC, would this also speed up the performance of my code? } thanks Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted June 3, 2008 Share Posted June 3, 2008 only need 5 out of 20 fields SELECT id, name, age, address, company FROM table1 would be better Second $query="SELECT table.id, table1.name, table2.age, table2.address FROM table1 left join table2 on table1.field1 = table2.field2" Quote Link to comment Share on other sites More sharing options...
billli Posted June 3, 2008 Author Share Posted June 3, 2008 Thanks. but say what if i need 19 columns from a table that has 20 columns? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 3, 2008 Share Posted June 3, 2008 I hate it when people change their stories halfway through a thread. It's pretty useless. If you need 19/20 columns, then just select all of them. Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted June 3, 2008 Share Posted June 3, 2008 Good Point what if then use the else statement. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.