Linked Questions
44 questions linked to/from Can you use an alias in the WHERE clause in mysql?
4 votes
2 answers
138 views
MySQL CASE WHEN where clause causes failure
I have a complex query that does multiple matches across multiple columns and then orders by relevance. Everything works fine UNTIL I add WHERE 'rank' > 0 This then returns an empty results set. ...
0 votes
1 answer
167 views
How to use alias variable for condition in mysql?
SELECT mob_no, (SELECT max(str_to_date(debit_date,'%d/%m/%Y')) FROM client_debit_bal WHERE mob_no='".$mobno."') AS date, sum(debit_amt) AS debit FROM client_debit_bal WHERE date_format(...
1 vote
4 answers
65 views
Where statement that will use a concat
SELECT zlec_status.nazwa AS Status, piorytet.nazwa AS Priorytet, Concat(koord.imie, ' ', koord.nazwisko) AS `Koordynator`, Concat(...
0 votes
1 answer
151 views
Innodb problem . The sql query with alias is not working
SELECT VoteTypeId AS vcol FROM VoteType v WHERE v.VoteTypeId = 4 and table structure is vcol VoteType ----------- -------------------------------------------------- 1 Yes/No 2 ...
0 votes
3 answers
142 views
Age calculation not working [duplicate]
I am receiving an error during my age calculation. Here is my query: SELECT (YEAR(CURDATE()) - YEAR(STR_TO_DATE(birthdate, '%m/%d/%Y'))) age, name FROM pers WHERE age >= 50 ORDER BY age DESC ...
2 votes
0 answers
172 views
MySQL 5.7 - aggregate function breaks referencing column alias in subquery
I've upgraded from MySQL 5.5 to 5.7 and I have a query that no longer works. It's quite a big one but I've reduced it down to this - the query itself doesn't really make sense but demonstrates: ...
-1 votes
3 answers
158 views
Sql query without sub query and joins
To have students (student_id, course_id, course_name) who take exactly only one course, using a simple SQL statement with no sub-query and no join at all student_id course_id course_name ----------...
0 votes
2 answers
110 views
Filtering data from joined mysql table using Where Clause
How to filter data in the below query using where clause for Balance column. I'm getting the error [Unknown column "Balance" in "where clause"] when i use Balance in where condition. select *,(it....
0 votes
1 answer
99 views
Reference a FROM alias in HAVING
Newbie to sql here. I am trying to select only tuples whose values in one column are larger than the average of that column. The problem is, the relation I am working with is created in the FROM ...
0 votes
2 answers
54 views
I dont understand what I did wrong
If I run below query in my phpmyadmin it throw me below error > Error in query (1054): Unknown column 'QTY' in 'where clause' SELECT User_Name, COUNT(User_Name) AS QTY FROM preusage WHERE ...
0 votes
2 answers
66 views
How to do a "where" clause on data from join
I am trying to do an SQL query to get all the messages sent between 2 users: the "Sender" and the "Reciever" (yes I know this is spelled wrong) are foreign keys to the Users table. I want to get back ...
0 votes
3 answers
91 views
Sql Query not working?
Why this query is not returning data of 2011 and 2012. Can anyone help me out.Thanks in advance. SELECT country_code, SUM(`attendance`) as k6_attendance, count(*) as total_events , ...
0 votes
0 answers
93 views
query 1 to Many in one record with filter in MariaDB
i've in a MariaDB's schema these tables: CLIENTI id | ragionesociale | idZucchetti | MORE COLS.... 1 | SEA srl | 569 | .... 2 | Contoso ...
1 vote
0 answers
79 views
Using a named count() function in sql where section
Is it possible to use an alias in a WHERE condition? For example: SELECT n.name, count(c.name) as freq FROM names as n, names as c WHERE freq < 1 AND gender = 'f' order by rand() ) Or would I ...