Hello All,
for()
{
SELECT * from x union select * from y union select * from z
}
I added union to all other queries which comes,when for loop runs but in my last line ,i've to remove the UNION ,how to do this.
Thanks in advance!
asked May 1, 2012 at 15:58
user1321210
-
4What are you trying to do? Could you try to explain a little more clearly please?dweiss– dweiss2012年05月01日 16:00:30 +00:00Commented May 1, 2012 at 16:00
-
What language is that? PHP? SQL? I don't think so.sh03– sh032012年05月01日 16:01:00 +00:00Commented May 1, 2012 at 16:01
1 Answer 1
You haven't given much information to work with, but I'm assuming you're starting with an array of query strings. If so, try this:
$queries = array();
$queries[] = "SELECT * FROM x";
$queries[] = "SELECT * FROM y";
$queries[] = "SELECT * FROM z";
$query = implode(" UNION ", $queries);
// $query now contains "SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM z"
answered May 1, 2012 at 16:02
Travesty3
14.5k7 gold badges64 silver badges103 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Travesty3
It's still very unclear to me what you're trying to do. Could you edit your question and include more detail and an expected result?
default