Why this (group) MySQL query doesn't work


Ilan Kleiman

I have this MySQL query but can't seem to solve it. I want it to group the "symbols" in the table "portfolio". ( SELECT symbol FROM portfolio GROUP BY symbol) though, I would like it to limit its search to: ( WHERE key = '$key' AND hash = '$hash' ORDER BY time DESC)

All in all, this is the whole query, although it gives me syntax errors at runtime, any help would be great.

SELECT symbol FROM portfolio GROUP BY symbol WHERE username = '$username' AND hash = '$hash' ORDER BY time DESC;
username

GROUP BYMust be placed after (or before) the ORDER BYclause.

Also, put the time between `` so that if you're using keywords from the SQL engine, there won't be a conflict.

Related


Why this (group) MySQL query doesn't work

Ilan Kleiman I have this MySQL query but can't seem to solve it. I want it to group the "symbols" in the table "portfolio". ( SELECT symbol FROM portfolio GROUP BY symbol) though, I would like it to limit its search to: ( WHERE key = '$key' AND hash = '$hash'

Mysql doesn't work in query using GROUP BY - why?

Orange 555 Weird wording " Notdoesn't work!" I know, but the strange thing is that the returned results do exist user_iddespite the query pointing to NOT (user_id = 1). SELECT post_id, last_update FROM the_table WHERE last_update BETWEEN N

Why doesn't this group by query work?

Joseph My query is not grouping correctly and returning wrong results, I can't figure out what the problem is. The query is as follows. FYI - the current form is unclear, the reason I need group by is because I removed all other parts of the query to find the

Why doesn't this GROUP BY query work?

thin tube I am using the following query to query an Access table: SELECT (VIN&' '&Make&' '&Model&' '&CarYear&' '&ExColor&' '&InColor&' ')as CarDescript FROM TestTable WHERE (WorkOrderNumber='$workorder') GROUP BY AssignedEmp; But simi

Why doesn't this group by query work?

Joseph My query is not grouping correctly and returning wrong results, I can't figure out what the problem is. The query is as follows. FYI - the current form is unclear, the reason I need group by is because I removed all other parts of the query to find the

Why Mysql order by doesn't work for this query

European users I have this query: SELECT * FROM ( SELECT p.id, product, unique_name, price, old_price, category_id, added_date FROM products p, products_to_categories ptc, products_to_adverts pta WHERE p.id=ptc.product_id AND (expire_date > now

Why Mysql order by doesn't work for this query

European users I have this query: SELECT * FROM ( SELECT p.id, product, unique_name, price, old_price, category_id, added_date FROM products p, products_to_categories ptc, products_to_adverts pta WHERE p.id=ptc.product_id AND (expire_date > now

Why comparing strings in MySQL query doesn't work

Rajan Benipuri I'm running a very simple SELECT query in MySQL and it doesn't work. SELECT string_name FROM table_name; This gives me the desired output. like This is string one. This is string two. This is string three. etc... but if I run a query like this

Why comparing strings in MySQL query doesn't work

Rajan Benipuri I'm running a very simple SELECT query in MySQL and it doesn't work. SELECT string_name FROM table_name; This gives me the desired output. like This is string one. This is string two. This is string three. etc... but if I run a query like this

why this query doesn't work

Nicoletta Sotiri I'm new to SQL so I don't understand why this query doesn't work. Thank you in advance CREATE VIEW temp AS SELECT return_date_time, renting_date_time FROM renting; CREATE TRIGGER charge_calc AFTER UPDATE ON renting.return_date_time FOR EACH R

Why doesn't this query work?

username Why does the following query not work in SQL Server 2008? SELECT CONVERT(INT, TEMP.observ_value) AS value FROM (SELECT observ_value FROM LAB_RESULTS WHERE observ_value NOT LIKE '%[^0-9]%') TEMP WHERE observ_value >= 190 Her

Why doesn't this query work?

username Why does the following query not work in SQL Server 2008? SELECT CONVERT(INT, TEMP.observ_value) AS value FROM (SELECT observ_value FROM LAB_RESULTS WHERE observ_value NOT LIKE '%[^0-9]%') TEMP WHERE observ_value >= 190 Her

MySQL query doesn't work with NOT IN

Hassan Hassan The query I wrote is not working my query: SELECT * FROM admin_marker WHERE admin_marker.city NOT IN (SELECT target FROM messsage) it says # 1267 - Illegal mix of collations (utf8_general_ci, IMPLICIT) and (utf8_unicode_ci, IMPLICIT) for opera

MySQL query doesn't work with NOT IN

Hassan Hassan The query I wrote is not working my query: SELECT * FROM admin_marker WHERE admin_marker.city NOT IN (SELECT target FROM messsage) it says # 1267 - Illegal mix of collations (utf8_general_ci, IMPLICIT) and (utf8_unicode_ci, IMPLICIT) for opera

mysql query doesn't work

Martin There is code for ajax in a separate sript including, $connection = mysqli_connect($db_config['server'],$db_config['db_user'],$db_config['db_pass']); if (!$connection) die('Could not connect to database: ' . mysql_error()); mysqli_select_db($conn

mysql query doesn't work

Martin There is code for ajax in a separate sript including, $connection = mysqli_connect($db_config['server'],$db_config['db_user'],$db_config['db_pass']); if (!$connection) die('Could not connect to database: ' . mysql_error()); mysqli_select_db($conn

MySQL query doesn't work with NOT IN

Hassan Hassan The query I wrote is not working my query: SELECT * FROM admin_marker WHERE admin_marker.city NOT IN (SELECT target FROM messsage) it says # 1267 - Illegal mix of collations (utf8_general_ci, IMPLICIT) and (utf8_unicode_ci, IMPLICIT) for opera

mysql query doesn't work

Martin There is code for ajax in a separate sript including, $connection = mysqli_connect($db_config['server'],$db_config['db_user'],$db_config['db_pass']); if (!$connection) die('Could not connect to database: ' . mysql_error()); mysqli_select_db($conn

Group by name in query formula doesn't work

Warren Melloni So I use a query function to count the number of instances where a particular name appears in column A of another sheet and display the result in column B of this sheet and the corresponding name in column A. Here is the function: =ArrayFormula(

Group by database query in laravel doesn't work

Zeeshan Nisar I am new to Laravel. I have a database table named A with column names 1,2,3 . In column 3 I have different values like a,b,c. Now what I want is to print out the total value of a, b and c using the group by clause. Sorry, my English is no good.

Group by name in query formula doesn't work

Warren Melloni So I use a query function to count the number of instances where a specific name appears in column A of another sheet and display the result in column B of this sheet and the corresponding name in column A. Here is the function: =ArrayFormula(QU

Group by name in query formula doesn't work

Warren Melloni So I use a query function to count the number of instances where a specific name appears in column A of another sheet and display the result in column B of this sheet and the corresponding name in column A. Here is the function: =ArrayFormula(QU

Group by name in query formula doesn't work

Warren Melloni So I use a query function to count the number of instances where a specific name appears in column A of another sheet and display the result in column B of this sheet and the corresponding name in column A. Here is the function: =ArrayFormula(QU

Group by expression doesn't work in this SQL query?

shamveel_ahammed I am new to SQL. Can anyone help me find out why the "Group By" expression is not working in this sql query? i get this error ERROR at line 3: ORA-00979: not a GROUP BY expression The code I am using is CREATE OR REPLACE VIEW CUSTOMER_LINE_IT

Why does this GROUP BY Mysql query not work?

username SELECT time.EmpID, time.Date, SUM(MinutesatState) AS active FROM time WHERE State = 'active' GROUP BY time.EmpID, time.Date; The above query works SELECT time.EmpID, time.Date, SUM(MinutesatState) AS idle FROM time WHERE State = 'idle' GROUP BY time.

Why does this GROUP BY Mysql query not work?

username SELECT time.EmpID, time.Date, SUM(MinutesatState) AS active FROM time WHERE State = 'active' GROUP BY time.EmpID, time.Date; The above query works SELECT time.EmpID, time.Date, SUM(MinutesatState) AS idle FROM time WHERE State = 'idle' GROUP BY time.

Why doesn't "COALESCE" work with "GROUP BY"?

John Alexander I have a table tablewith the following data: +----------+------+----------+ | location | sold | scrapped | +----------+------+----------+ | Paris | 5 | NULL | | Paris | NULL | 6 | +----------+------+----------+ I want this:

Why doesn't "COALESCE" work with "GROUP BY"?

John Alexander I have a table tablewith the following data: +----------+------+----------+ | location | sold | scrapped | +----------+------+----------+ | Paris | 5 | NULL | | Paris | NULL | 6 | +----------+------+----------+ I want this: