Urgent solution: MYSQL multi-condition query problem
Three conditions are available. the expected functions are as follows: input condition 1: query results that meet condition 1; input condition 2: query results that meet condition 2; input condition 3, query the results that meet condition 3. input conditions 1 and 2. query the results that meet condition 1 and 2. input conditions 1 and 3. query the results that meet condition 1 and 3; input conditions 2, 3: query results that meet conditions 2 and 3; input conditions 1, 2, and 3: query results that meet conditions 1 and 2. Result 3: Code is pasted out. There are seven tables in total. I don't know how to write the following conditions? Can this code be optimized? Solve it !!
$ Result = mysql_query ("SELECT m. tableMode, m. tableModeNote, c. tablechannel, o. tableOperator
FROM mode_table as m, mode_operator_relation as mo, operator_table as o, mode_provider_relation as mp,
Provider_table as p, channel_provider_relation as cp, channel_table as c
WHERE mo. tableModeId = m. tableModeId
AND o. tableOpeId = mo. tableOpeId
AND mp. tableModeId = m. tableModeId
AND mp. tableProId = p. tableProId
AND p. tableProId = cp. tableProId
AND cp. tableChaId = c. tableChaId
AND condition 1 condition 2 condition 3
Reply to discussion (solution)
If (condition 1 ){
$ SQL. = "and xxx1 ";
}
If (condition 2 ){
$ SQL. = "and xxx2 ";
}
If (condition 3 ){
$ SQL. = "and xxx3 ";
}
SQL statement optimization follows explain
If (condition 1 ){
$ SQL. = "and xxx1 ";
}
If (condition 2 ){
$ SQL. = "and xxx2 ";
}
If (condition 3 ){
$ SQL. = "and xxx3 ";
}
SQL statement optimization follows explain
Thank you. I have written this. Just sent a help post, you can help me answer the http://bbs.csdn.net/topics/391885406
You can use different conditions to call different statements.
You can use different conditions to call different statements.
Thank you. I have written this article. it's a great method!