Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 978
  • Last Modified:

using alias and wildcards in SELECT


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 products.id = 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?
2 Solutions
You would have to name all the select fields if you have fields in the tables that are the same.
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?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
> 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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

dog_starAuthor Commented:
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 :)
dog_starAuthor Commented:
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 products.id = related_id AND products.show_ = true

this seems to give me all fields for both tables.

thanks all for your help :)
dog_star, no worries. Glad to have helped :)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now