SQL query statement: SELECT * from Table wher A B C D

Source: Internet
Author: User
Request a SQL query statement: SELECT * from Table wher a B C D
SELECT * from Table wher A and B and C and D

Among them, A,b,c,d is the condition. How should it be constructed?

is not to judge A,b,c,d, as long as there is a not empty, then the "where"

And what about it? 》

------Solution--------------------
Determines non-null, misspelled SQL strings. Typically, where and a are not present, where and A are 1=1.
------Solution--------------------
Hookee () Positive solution
------Solution--------------------
Hookee () Positive solution

where 1=1 and where 1! = 1 are often used in SQL

1=1 for the back add things to pave, 1! = 1 Get the structure of the table
------Solution--------------------
$aWhere [] = "1=1";
if (!empty ($A))
$aWhere [] = $A;
if (!emtpy ($B))
$aWhere [] = $B;
if (!empty ($C))
$aWhere [] = $C;
if (!empty ($D))
$aWhere [] = $D;

$sWhere = Join (' and ', $aWhere);
$SSQL = "SELECT * from the TBL where $sWhere order by id DESC";

------Solution--------------------
$condition = "";
$link _symbol = "";
if ($a)
{
$condition. = "$link _symbol $a";
$link _symbol = "and";
}
In turn
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.