Wild card aliases...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Gardner

    Wild card aliases...

    Greetings:

    Is there a way to do <snip>SELECT table.* AS alias.*</snip>, or do I
    have to write additional code to automate the process?
    --

    Regards,

    Jeff Gardner
    _______________ ____________

    "Contrary to popular belief, Unix is user friendly. It just happens
    to be very selective about who its friends are." --Kyle Hearn
  • Erwin Moller

    #2
    Re: Wild card aliases...

    Jeff Gardner wrote:
    Greetings:
    >
    Is there a way to do <snip>SELECT table.* AS alias.*</snip>, or do I
    have to write additional code to automate the process?
    Which database are you using and what do you want to accomplish?

    Two concepts that may be interest:
    Alias:

    You can use an alias like this:
    SELECT U.username, U.userpass, I.total FROM tblUsers AS U, tblItems AS I
    WHERE (U.userid=I.use rid);

    So you name the tables, and tell the database which column to use.
    This can come in handy in many situations, eg if you use the same table 2
    times in your query.

    Derived table:
    consider a complex query:
    (SELECT U.userid, MAX(U.orderedIt ems) AS maxOrd FROM tbluser AS U WHERE
    (blabla) AND (blabla))

    You can use the RESULTS of that query as a real table by giving it a name.
    SO you get constructs like:
    SELECT U.userid, I.orderedItems, DRV1.maxInJanua ry
    FROM
    tbluser AS U,
    tblItems AS I,
    (bigqueryhere) AS DRV1
    WHERE (
    (U.userid=I.use rid) AND
    (DRV1.maxInJanu ary < 10)
    )

    In that way you can use the results from a query as a real table.

    Regards,
    Erwin Moller

    Comment

    • Jeff Gardner

      #3
      Re: Wild card aliases...

      Erwin Moller wrote:
      Jeff Gardner wrote:
      >
      >Greetings:
      >>
      >Is there a way to do <snip>SELECT table.* AS alias.*</snip>, or do I
      >have to write additional code to automate the process?
      >
      Which database are you using and what do you want to accomplish?
      >
      Two concepts that may be interest:
      Alias:
      >
      You can use an alias like this:
      SELECT U.username, U.userpass, I.total FROM tblUsers AS U, tblItems AS I
      WHERE (U.userid=I.use rid);
      >
      So you name the tables, and tell the database which column to use.
      This can come in handy in many situations, eg if you use the same table 2
      times in your query.
      >
      Derived table:
      consider a complex query:
      (SELECT U.userid, MAX(U.orderedIt ems) AS maxOrd FROM tbluser AS U WHERE
      (blabla) AND (blabla))
      >
      You can use the RESULTS of that query as a real table by giving it a name.
      SO you get constructs like:
      SELECT U.userid, I.orderedItems, DRV1.maxInJanua ry
      FROM
      tbluser AS U,
      tblItems AS I,
      (bigqueryhere) AS DRV1
      WHERE (
      (U.userid=I.use rid) AND
      (DRV1.maxInJanu ary < 10)
      )
      >
      In that way you can use the results from a query as a real table.
      >
      Regards,
      Erwin Moller
      More specifically, I would like to assign aliases as such: SELECT
      table1.*, table2.* AS alias1.*, alias2.* Many of the fields in the two
      tables being queried have the same name (ie address, phone1, etc.).
      Maybe, in my ignorance, I'm missing the point here. What I want to do
      is reference table1.address and table2.address in my output after the
      query is performed. What I am hoping to avoid is creating aliases for
      every instance of same name fields.

      --

      Regards,

      Jeff Gardner
      _______________ ____________

      "Contrary to popular belief, Unix is user friendly. It just happens
      to be very selective about who its friends are." --Kyle Hearn

      Comment

      • Jeff Gardner

        #4
        Re: Wild card aliases...

        Erwin Moller wrote:
        Jeff Gardner wrote:
        >
        >Greetings:
        >>
        >Is there a way to do <snip>SELECT table.* AS alias.*</snip>, or do I
        >have to write additional code to automate the process?
        >
        Which database are you using and what do you want to accomplish?
        >
        Two concepts that may be interest:
        Alias:
        >
        You can use an alias like this:
        SELECT U.username, U.userpass, I.total FROM tblUsers AS U, tblItems AS I
        WHERE (U.userid=I.use rid);
        >
        So you name the tables, and tell the database which column to use.
        This can come in handy in many situations, eg if you use the same table 2
        times in your query.
        >
        Derived table:
        consider a complex query:
        (SELECT U.userid, MAX(U.orderedIt ems) AS maxOrd FROM tbluser AS U WHERE
        (blabla) AND (blabla))
        >
        You can use the RESULTS of that query as a real table by giving it a name.
        SO you get constructs like:
        SELECT U.userid, I.orderedItems, DRV1.maxInJanua ry
        FROM
        tbluser AS U,
        tblItems AS I,
        (bigqueryhere) AS DRV1
        WHERE (
        (U.userid=I.use rid) AND
        (DRV1.maxInJanu ary < 10)
        )
        >
        In that way you can use the results from a query as a real table.
        >
        Regards,
        Erwin Moller
        More specifically, I would like to assign aliases as such: SELECT
        table1.*, table2.* AS alias1.*, alias2.* Many of the fields in the two
        tables being queried have the same name (ie address, phone1, etc.).
        Maybe, in my ignorance, I'm missing the point here. What I want to do
        is reference table1.address and table2.address in my output after the
        query is performed. What I am hoping to avoid is creating aliases for
        every instance of same name fields.

        Using php 5.1.6 and mysql 5.0.24a

        --

        Regards,

        Jeff Gardner
        _______________ ____________

        "Contrary to popular belief, Unix is user friendly. It just happens
        to be very selective about who its friends are." --Kyle Hearn

        Comment

        • Jerry Stuckle

          #5
          Re: Wild card aliases...

          Jeff Gardner wrote:
          Erwin Moller wrote:
          >
          >Jeff Gardner wrote:
          >>
          >>Greetings:
          >>>
          >>Is there a way to do <snip>SELECT table.* AS alias.*</snip>, or do I
          >>have to write additional code to automate the process?
          >>
          >>
          >Which database are you using and what do you want to accomplish?
          >>
          >Two concepts that may be interest:
          >Alias:
          >>
          >You can use an alias like this:
          >SELECT U.username, U.userpass, I.total FROM tblUsers AS U, tblItems AS
          >I WHERE (U.userid=I.use rid);
          >>
          >So you name the tables, and tell the database which column to use.
          >This can come in handy in many situations, eg if you use the same
          >table 2 times in your query.
          >>
          >Derived table:
          >consider a complex query:
          >(SELECT U.userid, MAX(U.orderedIt ems) AS maxOrd FROM tbluser AS U
          >WHERE (blabla) AND (blabla))
          >>
          >You can use the RESULTS of that query as a real table by giving it a
          >name.
          >SO you get constructs like:
          >SELECT U.userid, I.orderedItems, DRV1.maxInJanua ry
          >FROM
          >tbluser AS U,
          >tblItems AS I,
          >(bigqueryher e) AS DRV1
          >WHERE (
          >(U.userid=I.us erid) AND
          >(DRV1.maxInJan uary < 10)
          >)
          >>
          >In that way you can use the results from a query as a real table.
          >>
          >Regards,
          >Erwin Moller
          >
          More specifically, I would like to assign aliases as such: SELECT
          table1.*, table2.* AS alias1.*, alias2.* Many of the fields in the two
          tables being queried have the same name (ie address, phone1, etc.).
          Maybe, in my ignorance, I'm missing the point here. What I want to do
          is reference table1.address and table2.address in my output after the
          query is performed. What I am hoping to avoid is creating aliases for
          every instance of same name fields.
          >
          Since this is a SQL question, you might try asking in a newsgroup
          related to your database. But from the PHP end, no, there is no way.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Erwin Moller

            #6
            Re: Wild card aliases...

            Jeff Gardner wrote:
            Erwin Moller wrote:
            >Jeff Gardner wrote:
            >>
            >>Greetings:
            >>>
            >>Is there a way to do <snip>SELECT table.* AS alias.*</snip>, or do I
            >>have to write additional code to automate the process?
            >>
            >Which database are you using and what do you want to accomplish?
            >>
            >Two concepts that may be interest:
            >Alias:
            >>
            >You can use an alias like this:
            >SELECT U.username, U.userpass, I.total FROM tblUsers AS U, tblItems AS I
            >WHERE (U.userid=I.use rid);
            >>
            >So you name the tables, and tell the database which column to use.
            >This can come in handy in many situations, eg if you use the same table 2
            >times in your query.
            >>
            >Derived table:
            >consider a complex query:
            >(SELECT U.userid, MAX(U.orderedIt ems) AS maxOrd FROM tbluser AS U WHERE
            >(blabla) AND (blabla))
            >>
            >You can use the RESULTS of that query as a real table by giving it a
            >name. SO you get constructs like:
            >SELECT U.userid, I.orderedItems, DRV1.maxInJanua ry
            >FROM
            >tbluser AS U,
            >tblItems AS I,
            >(bigqueryher e) AS DRV1
            >WHERE (
            >(U.userid=I.us erid) AND
            >(DRV1.maxInJan uary < 10)
            >)
            >>
            >In that way you can use the results from a query as a real table.
            >>
            >Regards,
            >Erwin Moller
            More specifically, I would like to assign aliases as such: SELECT
            table1.*, table2.* AS alias1.*, alias2.* Many of the fields in the two
            tables being queried have the same name (ie address, phone1, etc.).
            Maybe, in my ignorance, I'm missing the point here. What I want to do
            is reference table1.address and table2.address in my output after the
            query is performed. What I am hoping to avoid is creating aliases for
            every instance of same name fields.
            Hi,

            No, that is not your ignorance but mine. I misinterpreted your question
            completely.
            So you want to 'massalias' all columns?
            I do not know of such a construct, and never had need for it either, but as
            Jerry wrote: try a mySQL oriented newsgroup, maybe they know over there.

            Regrads,
            Erwin Moller
            >
            Using php 5.1.6 and mysql 5.0.24a
            >

            Comment

            • Petr Vileta

              #7
              Re: Wild card aliases...

              Jeff Gardner wrote:
              More specifically, I would like to assign aliases as such: SELECT
              table1.*, table2.* AS alias1.*, alias2.* Many of the fields in the
              two tables being queried have the same name (ie address, phone1,
              etc.). Maybe, in my ignorance, I'm missing the point here. What I
              want to do is reference table1.address and table2.address in my
              output after the query is performed. What I am hoping to avoid is
              creating aliases for every instance of same name fields.
              >
              If I know it is not possible in MySQL. If you have for example
              table1 (partno int(5), string varchar(100))
              table2 (mykey int(5), string varchar(200))
              and you want to select all from both tables, you must write some like this
              select partno,mykey,ta ble1.string,tab le2.string from table1,table2 where
              ....

              --

              Petr Vileta, Czech republic
              (My server rejects all messages from Yahoo and Hotmail. Send me your mail
              from another non-spammer site please.)



              Comment

              Working...