0

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!

2
  • 4
    What are you trying to do? Could you try to explain a little more clearly please? Commented May 1, 2012 at 16:00
  • What language is that? PHP? SQL? I don't think so. Commented May 1, 2012 at 16:01

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

2 Comments

:I want to remove the union only in the ueries[n] means the last line of the total no of queries.
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.