Jump to content

asterisk in mysql_query()


niche

Recommended Posts

I'm under the impression that the asterisk in this command includes every single column for that table.If so how would I rewrite this command to only include the two relevant columns (begin and end)?i.e.: $result = mysql_query("SELECT * FROM plan WHERE DATE('2010-10-05 00:00:00') BETWEEN DATE(begin) AND DATE(end)")Is there a W3school reference for this task of other ref if w3s not avail? Is the non-asterisk approach faster?Thanks

Link to comment
Share on other sites

You just separate the column names with commas. It's typically more efficient to only select what you need instead of everything. If you want to speed up the search you can also define indexes on each column in the WHERE clause.

Link to comment
Share on other sites

This works:$result = mysql_query("SELECT * FROM plan WHERE DATE('2010-10-10 00:00:00') BETWEEN DATE(begin) AND DATE(end)");This didn't:$result = mysql_query("SELECT begin, end FROM plan WHERE DATE('2010-10-10 00:00:00') BETWEEN DATE(begin) AND DATE(end)");Or, is there a conflict between specifying columns and using WHERE?

Link to comment
Share on other sites

Seems $results limited the returned array to the specified columns (I should have thought/know that) while the code I used also required additional keys to be present in the array. I added additional fields to be selected and Voila!Lessen learned. I think. Please let me know if not or if you have additional info.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...