Why do I get the output of SELECT on 2 lines in mysql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar abbas
    New Member
    • Nov 2010
    • 1

    #1

    Why do I get the output of SELECT on 2 lines in mysql?

    hi,
    i wrote this code in mysql:

    create table bag1 (imsi varchar(20) , bserv varchar(20) , msisdn varchar(20) , vlr varchar(20) );
    create table bag3 (imsi varchar(20) , bserv varchar(20) , msisdn varchar(20) , vlr varchar(20) );
    SELECT bag1.imsi , bag1.msisdn , bag1.vlr , "hlrbag1" , "MTN"
    FROM bag1
    where (bag1.vlr like "98935%") and (bag1.bserv="T1 1")
    union
    SELECT bag1.imsi , bag1.msisdn , bag1.vlr , "hlrbag1" , "Talia"
    FROM bag1
    where (bag1.vlr like "98932%") and (bag1.bserv="T1 1");

    i need to put 2 new coulomns with the words "hlrbag1" and "MTN" next to each line outpout from SELECT, thats why i wrote "hlrbag1" , "MTN" at the end of the SELECT statement, the output i get is fine except that i get it on 2 separate lines , i need to have the output on one line. here is what i get:
    imsi msisdn vlr hlrbag1 Iran_MTN
    41820105 9647803 989350002
    hlrbag1 MTN
    41820806 96478086 9893500021
    hlrbag1 Talia

    i need it to be looks like this:
    imsi msisdn vlr hlrbag1 MTN
    41820105 9647803 989350002 hlrbag1 MTN
    41820806 96478086 9893500021 hlrbag1 Talia

    is it possible?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You haven't stated where the output is going.
    But try giving the columns names
    Code:
    SELECT bag1.imsi , bag1.msisdn , bag1.vlr , "hlrbag1" AS hlr , "MTN" AS mtn

    Comment

    Working...