SQL query statement: select * fromTablewherABCD

Source: Internet
Author: User
Find an SQL query statement: select * fromTablewherABCDselect & nbsp; * & nbsp; from & nbsp; Table & nbsp; wher & nbsp; A & nbsp; and & nbsp; B & nbsp; and & nbsp; C & nbsp; and & nbsp; D find an SQL query statement: select * from Table wher A B C D
Select * from Table wher A and B and C and D

Where A, B, C, and D are the conditions. How should we construct it?

Is it necessary to first judge a, B, c, d, as long as one is not empty, then "where"

What about AND?

------ Solution --------------------
Judge whether it is not empty, spell the SQL string. generally, add where 1 = 1 First, no where and A will appear
------ Solution --------------------
Hookee () positive solution
------ Solution --------------------
Hookee () positive solution

Where 1 = 1 and where 1! = 1 is often used in SQL

1 = 1 pave the way for adding things to the back, 1! = 1 to get the table structure
------ Solution --------------------
$ AWhere [] = "1 = 1 ";
If (! Empty ($ ))
$ AWhere [] = $;
If (! Emtpy ($ B ))
$ AWhere [] = $ B;
If (! Empty ($ C ))
$ AWhere [] = $ C;
If (! Empty ($ D ))
$ AWhere [] = $ D;

$ SWhere = join ('and', $ aWhere );
$ SSql = "select * from tbl where $ sWhere order by id desc ";

------ Solution --------------------
$ Condition = "";
$ Link_symbol = "";
If ($)
{
$ Condition. = "$ link_symbol $ ";
$ Link_symbol = "and ";
}
And so on

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.