Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Subquery help
- Evil Bert
February 7, 2006, 4:30 am
rate this thread
I have this sql statement:
FROM affiliates_referrals, applications
WHERE affiliates_referrals.application_id =
AND applications.status =2
ORDER BY affiliates_referrals.timestamp DESC
and I am trying to reverse the order of it by doing this for display
SELECT * FROM (SELECT * FROM affiliates_referrals, applications WHERE
affiliates_referrals.application_id = applications.application_id AND
applications.status = 2 ORDER BY affiliates_referrals.timestamp DESC
LIMIT 50) AS x ORDER BY timestamp DESC
I get a "Column 'timestamp' in order clause is ambiguous" error to do
with the "ORDER BY timestamp DESC" part. I've tried putting
applications.timestamp and affiliates_referrals.timestamp but that
doesn't work either. This subquery worked fine with a single table but
it doesn't work with 2 tables being joined. It's probably something
simple but I just can't figure it out. TIA!
Re: Subquery help
i'm not entirely sure what you are trying to do, but, if you are only trying
to reverse the order why not do...
ORDER BY affiliates_referrals.timestamp ASC ?
probably this is not what you are trying to do, would you mind explaining
further? also, sub-selects are used in WHERE clauses when you need to run a
query that matches the result of another query
SELECT column_name FROM table_name
WHERE column_name =
WHERE other_column <some criteria>
Re: Subquery help
I assume you meant that one of those orderings should be ASC. Otherwise you
aren't reversing the order, and you might as well have used your original
Is there a timestamp column in both tables? If so, you could have two
columns coming out of the subquery with the same name. You might need to
replace your "SELECT *" with an explicit list of columns, and use AS to
rename the ones with duplicate names.
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum