Jump to content

Complex SQL Query Help Needed


Pi_Mastuh

Recommended Posts

I am trying to run a rather complex query, and am getting the error: "Every derived table must have its own alias."

 

I haven't done this kind of complex SQL before, could somebody tell me what I'm missing here?

 

Thanks!

 

$SQL2 = "SELECT * FROM shiftsIn WHERE date='$day' AND month='$month' AND year='$year' AND busID='$userBusID'";
$SQL = "SELECT * FROM ($SQL2) WHERE (startTime<='$startTime2' AND endTime>='$endTime2') OR (startTime IS NULL AND endTime IS NULL)";
$resultShifts = mysql_query($SQL,$connection) or die(mysql_error());
$numShifts = mysql_num_rows($resultShifts);

 

Link to comment
https://forums.phpfreaks.com/topic/225987-complex-sql-query-help-needed/
Share on other sites

:confused:

 

the explanation for the error code is very simple..

http://dev.mysql.com/doc/refman/5.0/en/from-clause-subqueries.html

 

however,,, is hard to understand what are you are trying to do using a sub-query when in reality that could be solved with ONE and simple query... just put the 2 WHERE together in one query string and "complexity" is gone

  • 2 weeks later...

Archived

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

×
×
  • 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.