using alias and wildcards in SELECT

Posted on 2009-04-21
Last Modified: 2012-05-06

i'm moving from using access as a backend for my websites to using mySQL... generally the SQL (so far) has been behaving itself, but i've come across a problem...

in access SQL you could use the following :

SELECT related_items.show_ AS RShow, products.show_ AS PShow, * FROM related_items, products WHERE product_id = "& varID &" AND = related_id AND products.show_ = true

this will return me all fields of both tables and gives an alias to the "show_" field because both tables have a field named like this...

this doesn't work in mySQL... i have to name all the fields in the SELECT....

does anyone know if there is a way to get this to work in mySQL, or should i just name all the SELECT fields?
Question by:dog_star
    LVL 16

    Expert Comment

    You would have to name all the select fields if you have fields in the tables that are the same.
    LVL 65

    Accepted Solution

    you have a * in your sql, i.e. selecting all fields
    from which table do you want to select all the fields from?
    perhaps prefix that with the table name?
    LVL 142

    Assisted Solution

    by:Guy Hengel [angelIII / a3]
    > i have to name all the fields in the SELECT

    please do so in all your databases/queries. using * is bad habit !
    there are exceptions to this, but this case does not look like one.

    Author Closing Comment

    thanks rockiroads, that worked well i think....

    @angellll... yes, i've been told this is bad practice.... one day i promise to get out of the habit :)

    Author Comment

    so yes, rockiroads suggestion seems to work...i changed the sql to the following :

    SELECT related_items.show_ AS RelatedShow, products.show_ AS ProdShow, products.*,related_items.*  FROM related_items, products WHERE product_id = 1 AND = related_id AND products.show_ = true

    this seems to give me all fields for both tables.

    thanks all for your help :)
    LVL 65

    Expert Comment

    dog_star, no worries. Glad to have helped :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Subquery Help! 9 37
    SQL Date from a string 4 41
    Format Number Field 10 34
    Number Format 1 31
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now