You can not use a column correlation name in other expressions, except in the order by clause.
The general technique is
select a + b
from (select <expression> as a, <expression> as b, ...
from ...) dt
It's called overlay in standard SQL. It has the bloated syntax
OVERLAY(<expression> PLACING <expression>
FROM <numeric value expression>
[FOR <numeric value expression>])
I haven't seen any DBMS with support for this.
Use of ` is not ANSI SQL compliant.
@lastID:=LAST_INSERT_ID() is not ANSI SQL compliant.
@ is not a valid character in an identifier.
LAST_INSERT_ID is a Mysql specific routine.
; is only used as delimiter between statements, not as a terminator.
If you have the data
dateColumn | rateColumn
------------------
2006-04-23 | 1234
2006-04-23 | 5678
what result do you want? It is not clear from your post.
SELECT SUM(pointsrecvd),userid
FROM tblPointSystem
group by userid
order by 1 desc
1 reflects the position in the select list of the item you wish to order by.
SELECT tbl1.id, name, t2.color
FROM tbl1 left join tbl2 t2 on tbl1.id = t2.t1_id
left join tbl2 t3 on t2.t1_id = t3.t1_id
and t3.color = 'green'
where t3.color is null
time to upgrade ...
SELECT tbl1.id, name, color
FROM tbl1 left join tbl2 on tbl1.id = tbl2.t1_id
where not exists
(select *
from tbl2
where tbl1.id = tbl2.id
and color = 'green')
The where clause is not in the wrong place. I typed the conditions incorrectly but it is located where I intended it to be. Note the use of a derived table.
select LastName, FirstName,
case when min(credentials.fk) is null
then 'No' else 'Yes' end as credentaials
from demographics left join credentials
on demographics.pk = credentials.fk
group by lastName,FirstName
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.