Jump to content

SELECTing data from MySql


billli

Recommended Posts

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

 

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.