this is the code what im using
$Last_Video = $db->fetch_all('
SELECT VID, thumb
FROM video
WHERE VID IN (
SELECT VID
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5)
ORDER BY RAND()
LIMIT 1
');
This is the error what give me
Message: Error during SQL execution: SELECT VID, thumb FROM video WHERE VID IN ( SELECT VID FROM video WHERE title LIKE "%funny%" ORDER BY viewtime DESC LIMIT 5) ORDER BY RAND() LIMIT 1<br />
MySQL Error: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'<br />
MySQL Errno: 1235
how i can fix this problem ? its other way to make it ... so i dont get the error ...
Instead of using IN, you can use JOIN
SELECT v.VID, v.thumb
FROM video AS v
INNER JOIN
(SELECT VID
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5) as v2
ON v.VID = v2.VID
ORDER BY RAND()
LIMIT 1
You can use below to bypass this error.
$Last_Video = $db->fetch_all('
SELECT VID, thumb
FROM video
WHERE VID IN (select * from (
SELECT VID
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5) temp_tab)
ORDER BY RAND()
LIMIT 1
');
You don't need a subquery here. Try this:
SELECT VID, thumb
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY RAND() DESC
LIMIT 1
In MySQL 5.0.26 and later, you will get an error:
MySQL does not support LIMIT in subqueries for certain subquery operators:
Reference.
add this is your in condition
(SELECT * FROM (
SELECT * FROM table ORDER BY id DESC LIMIT 50
) sub
ORDER BY id ASC)
Why you cant use simple: ?
SELECT v.VID, v.thumb
FROM video as v
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5
what for subqueries here?
mysql is disabled read it ORACLE
DELETE FROM wall_orders WHERE order_id IN (
SELECT order_id FROM (SELECT order_id, COUNT(orders_products_id) as cnt FROM wall_orders_products GROUP BY order_id ORDER BY cnt DESC LIMIT 1000) y1 WHERE cnt > 170 LIMIT 1000)
235 - This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
Simple SQL and not possible
Related
this is the code what im using
$Last_Video = $db->fetch_all('
SELECT VID, thumb
FROM video
WHERE VID IN (
SELECT VID
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5)
ORDER BY RAND()
LIMIT 1
');
This is the error what give me
Message: Error during SQL execution: SELECT VID, thumb FROM video WHERE VID IN ( SELECT VID FROM video WHERE title LIKE "%funny%" ORDER BY viewtime DESC LIMIT 5) ORDER BY RAND() LIMIT 1<br />
MySQL Error: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'<br />
MySQL Errno: 1235
how i can fix this problem ? its other way to make it ... so i dont get the error ...
Instead of using IN, you can use JOIN
SELECT v.VID, v.thumb
FROM video AS v
INNER JOIN
(SELECT VID
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5) as v2
ON v.VID = v2.VID
ORDER BY RAND()
LIMIT 1
You can use below to bypass this error.
$Last_Video = $db->fetch_all('
SELECT VID, thumb
FROM video
WHERE VID IN (select * from (
SELECT VID
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5) temp_tab)
ORDER BY RAND()
LIMIT 1
');
You don't need a subquery here. Try this:
SELECT VID, thumb
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY RAND() DESC
LIMIT 1
In MySQL 5.0.26 and later, you will get an error:
MySQL does not support LIMIT in subqueries for certain subquery operators:
Reference.
add this is your in condition
(SELECT * FROM (
SELECT * FROM table ORDER BY id DESC LIMIT 50
) sub
ORDER BY id ASC)
Why you cant use simple: ?
SELECT v.VID, v.thumb
FROM video as v
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5
what for subqueries here?
mysql is disabled read it ORACLE
DELETE FROM wall_orders WHERE order_id IN (
SELECT order_id FROM (SELECT order_id, COUNT(orders_products_id) as cnt FROM wall_orders_products GROUP BY order_id ORDER BY cnt DESC LIMIT 1000) y1 WHERE cnt > 170 LIMIT 1000)
235 - This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
Simple SQL and not possible
I am attempting to combine three queries into one and failing miserably. Everything goes well until I add the "order by" clause.
SELECT
wti.price, hh.price, mb.price
FROM
spotprices.wti, spotprices.hh, spotprices.mb
ORDER BY
wti.sdate desc limit 1, hh.sdate desc limit 1, mb.sdate desc limit 1;
In essence, I am attempting to get the most recent price by sdate by using the "order by sdate desc limit 1" trick. Individually, the query works well.
SELECT price FROM spotprices.wti ORDER BY wti.sdate desc LIMIT 1;
Use subqueries in the select:
SELECT (SELECT wti.price FROM spotprices.wti ORDER BY wti.sdate DESC LIMIT 1) as wti_price,
(SELECT hh.price FROM spotprices.hh ORDER BY hh.sdate DESC LIMIT 1) as hh_price,
(SELECT mb.price FROM spotprices.mb ORDER BY mb.sdate DESC LIMIT 1) as mb_price;
The query is:
SELECT
*
FROM
press_release
WHERE
posted_by != '1' AND
LOCATE('1',send_id)
ORDER BY
date_added DESC
LIMIT 0,10
when i run these query in PHP my admin it will give me 2 rows but i run these query with MySQL_query() it will give me zero rows. Why?
check if mysql_error() returns an error. Instead of using LOCATE('1',send_id) have you tried using the following:
SELECT * FROM press_release WHERE posted_by != '1' AND send_id = 1 ORDER BY date_added DES C LIMIT 0,10
Error is in your query
your Query
SELECT * FROM press_release WHERE posted_by != '1' AND LOCATE('1',send_id) ORDER BY date_added DES C LIMIT 0,10
Which should be
SELECT * FROM press_release WHERE posted_by <> '1' AND LOCATE('1',send_id) ORDER BY date_added DESC LIMIT 0,10
Mysql not equal to sign is not != it should be <> and your DESC have an space
Is there a way to do this without two selects ?
Original query
SELECT name,view_count
FROM `ex`.`item`
where status='available' order by view_count asc
limit 40;
To display randomly
SELECT *
FROM (SELECT name,view_count
FROM `ex`.`item`
where status='available'
order by view_count asc
limit 40 ) AS temp
ORDER BY RAND();
Can this be done without a second select?
Try this:
SQL Fiddle: http://sqlfiddle.com/#!2/330f8/2
SELECT name, view_count
FROM `ex`.`item`
where status='available'
order by rand(), view_count asc limit 40;
I'm using an union statement in mysql but i've some problems sorting the results. The ORDER statement doesn't works at all, the results comes out always sorted by the id field.
Here an example query:
SELECT a.* FROM ( ( select * from ticket_ticket AS t1 WHERE ticket_active=1 ORDER BY t1.ticket_date_last_modified DESC )
UNION ( select * from ticket_ticket AS t2 WHERE ticket_active=0 ORDER BY t2.ticket_date_last_modified DESC, t2.ticket_status_id DESC ) )
AS a LIMIT 0,20;
I want to order the results of the first SELECT by last_modified time, and the second SELECT by time and status. But the ORDER statement get just skipped. The results always come out ordered by the ticket_id ( the PRIMARY KEY ).
What's wrong in this query ?
Thanks!
Ok, i've fixed it writing the query this way:
SELECT a.*
FROM
(SELECT *
FROM ticket_ticket
WHERE ticket_active=1
ORDER BY ticket_date_last_modified DESC) AS a
UNION ALL
SELECT b.*
FROM
(SELECT *
FROM ticket_ticket
WHERE ticket_active=0
ORDER BY ticket_date_last_modified DESC, ticket_status_id DESC) AS b LIMIT 0,
20;
You are using a UNION query that will return distinct values, and the order of the returned rows is not guaranteed.
But you don't need an union query for this:
select *
from ticket_ticket AS t1
ORDER BY
ticket_active!=1,
ticket_date_last_modified DESC,
ticket_status_id DESC
LIMIT 0,20;