niche Posted October 6, 2012 Share Posted October 6, 2012 (edited) The result of this code: $plan_trkg = mysql_query("SELECT plan.*, trkg.curwipprice_online, trkg.addrFROM planLEFT JOIN trkgON plan.cliorder = trkg.cliorderWHERE (trkg.addr = '5740 OLD CHENEY RD')OR (plan.cliorder != '' AND plan.enabled != '0000-00-00 00:00:00' AND TIMESTAMP(NOW()) BETWEEN TIMESTAMP(plan.begin) AND TIMESTAMP(plan.end)) ORDER BY ((1-(trkg.curwipprice_online/plan.edprice))*100) DESC, id ASC, ((1-(plan.curwipprice/plan.edprice))*100) DESC ")or die(mysql_error()); Produces this echo:Superboy and His Dog Krypto ----------5740 OLD CHENEY RDWonder Woman----------5740 OLD CHENEY RDCreature from the Black Lagoon ----------5740 OLD CHENEY RDSeaview 8-Window----------5740 OLD CHENEY RDPeterbilt 377 A/E ----------1840 Pawnee StF-86F Sabre----------1840 Pawnee StSherman III----------5740 OLD CHENEY RDNakajima Ki-84----------5740 OLD CHENEY RDPanther G----------5740 OLD CHENEY RDPeterbilt 377 A/E ----------5740 OLD CHENEY RDF-86F Sabre----------5740 OLD CHENEY RDPeterbilt 353 ----------1840 Pawnee StPeterbilt 353 ----------5740 OLD CHENEY RD How do I get the "1840 Pawnee St" out of the selection from the right table? I thought the OR would do that. Edited October 6, 2012 by niche Link to comment Share on other sites More sharing options...
niche Posted October 6, 2012 Author Share Posted October 6, 2012 (edited) It's pretty obscure, but this provided the answer: http://dev.mysql.com....0/en/join.html The conditional_expr used with ON is any conditional expression of the form that can be used in a WHERE clause. Generally, you should use the ON clause for conditions that specify how to join tables, and the WHERE clause to restrict which rows you want in the result set. .. and this code (note placement of the AND - it was previously in the WHERE:SELECT plan.*, trkg.curwipprice_online, trkg.addrFROM planLEFT JOIN trkgON plan.cliorder = trkg.cliorderAND trkg.addr = '5740 OLD CHENEY RD'WHERE (TIMESTAMP(NOW()) BETWEEN TIMESTAMP(plan.begin) AND TIMESTAMP(plan.end) )ORDER BY ((1-(trkg.curwipprice_online/plan.edprice))*100) DESC, id ASC, ((1-(plan.curwipprice/plan.edprice))*100) DESC Edited October 6, 2012 by niche Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now