Jump to content

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