Mysql Update column with subrequest Order By2019 Community Moderator ElectionHow do you set a default value for a MySQL Datetime column?How to find all the tables in MySQL with specific column names in them?How do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How do I specify unique constraint for multiple columns in MySQL?How to get a list of MySQL user accountsInsert into a MySQL table or update if existsHow to reset AUTO_INCREMENT in MySQL?MySQL error code: 1175 during UPDATE in MySQL WorkbenchHow to import an SQL file using the command line in MySQL?
My adviser wants to be the first author
How to deal with a cynical class?
Why do passenger jet manufacturers design their planes with stall prevention systems?
Where is the 1/8 CR apprentice in Volo's Guide to Monsters?
Identifying the interval from A♭ to D♯
Informing my boss about remarks from a nasty colleague
Know when to turn notes upside-down(eighth notes, sixteen notes, etc.)
Why doesn't the EU now just force the UK to choose between referendum and no-deal?
Can elves maintain concentration in a trance?
How to answer questions about my characters?
Welcoming 2019 Pi day: How to draw the letter π?
How to deal with taxi scam when on vacation?
Bash: What does "masking return values" mean?
How is the Swiss post e-voting system supposed to work, and how was it wrong?
Is a lawful good "antagonist" effective?
How to make healing in an exploration game interesting
Why do Australian milk farmers need to protest supermarkets' milk price?
Do I need life insurance if I can cover my own funeral costs?
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
What are some nice/clever ways to introduce the tonic's dominant seventh chord?
Why are the outputs of printf and std::cout different
Latest web browser compatible with Windows 98
It's a yearly task, alright
Calculus II Professor will not accept my correct integral evaluation that uses a different method, should I bring this up further?
Mysql Update column with subrequest Order By
2019 Community Moderator ElectionHow do you set a default value for a MySQL Datetime column?How to find all the tables in MySQL with specific column names in them?How do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How do I specify unique constraint for multiple columns in MySQL?How to get a list of MySQL user accountsInsert into a MySQL table or update if existsHow to reset AUTO_INCREMENT in MySQL?MySQL error code: 1175 during UPDATE in MySQL WorkbenchHow to import an SQL file using the command line in MySQL?
I have a table biblek2 items with those 4 columns :
id (autoincrement)
catid(int)
introtext(varchar)
ordering(int)
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 1 ║ 3024 ║ orange ║ 122 ║
║ 2 ║ 2024 ║ zebra ║ 45 ║
║ 3 ║ 3010 ║ juice ║ 55 ║
║ 4 ║ 3002 ║ build ║ 17 ║
║ 5 ║ 2003 ║ car ║ 87 ║
║ 6 ║ 1610 ║ other ║ 1521 ║
║ 7 ║ 1620 ║ other ║ 200 ║
╚════╩═══════╩═══════════╩══════════╝
I expect that
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 5 ║ 2003 ║ car ║ 1 ║
║ 4 ║ 3002 ║ build ║ 2 ║
║ 3 ║ 3010 ║ juice ║ 3 ║
║ 1 ║ 3024 ║ orange ║ 4 ║
║ 2 ║ 2024 ║ zebra ║ 5 ║
╚════╩═══════╩═══════════╩══════════╝
I want to
select * from biblek2_items where catid between 2001 and 3024
ORDER BY introtext ASC
- empty the ordering column
- reorder the ordering column by increment from 1 to n according to the result of the order column
I tried this with no success
DECLARE @variable int
SET @variable = 0
UPDATE `biblek2_items`
SET @variable = ordering = @variable + 1
WHERE ordering IN (SELECT ordering
FROM `biblek2_items`
WHERE catid BETWEEN 2001 AND 3024
ORDER BY `introtext` DESC)
I read in the forum that MySQL can't allow subrequests with ORDER BY, so could you help me
mysql
add a comment |
I have a table biblek2 items with those 4 columns :
id (autoincrement)
catid(int)
introtext(varchar)
ordering(int)
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 1 ║ 3024 ║ orange ║ 122 ║
║ 2 ║ 2024 ║ zebra ║ 45 ║
║ 3 ║ 3010 ║ juice ║ 55 ║
║ 4 ║ 3002 ║ build ║ 17 ║
║ 5 ║ 2003 ║ car ║ 87 ║
║ 6 ║ 1610 ║ other ║ 1521 ║
║ 7 ║ 1620 ║ other ║ 200 ║
╚════╩═══════╩═══════════╩══════════╝
I expect that
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 5 ║ 2003 ║ car ║ 1 ║
║ 4 ║ 3002 ║ build ║ 2 ║
║ 3 ║ 3010 ║ juice ║ 3 ║
║ 1 ║ 3024 ║ orange ║ 4 ║
║ 2 ║ 2024 ║ zebra ║ 5 ║
╚════╩═══════╩═══════════╩══════════╝
I want to
select * from biblek2_items where catid between 2001 and 3024
ORDER BY introtext ASC
- empty the ordering column
- reorder the ordering column by increment from 1 to n according to the result of the order column
I tried this with no success
DECLARE @variable int
SET @variable = 0
UPDATE `biblek2_items`
SET @variable = ordering = @variable + 1
WHERE ordering IN (SELECT ordering
FROM `biblek2_items`
WHERE catid BETWEEN 2001 AND 3024
ORDER BY `introtext` DESC)
I read in the forum that MySQL can't allow subrequests with ORDER BY, so could you help me
mysql
the ORDER BY in the subquery makes no sense anyway, because, you don't LIMIT. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN in your main query.
– Thomas G
Mar 7 at 12:30
It looks like you mixed up the order of car and build in your results. Which MySQL version are you using?
– Thorsten Kettner
Mar 7 at 13:13
add a comment |
I have a table biblek2 items with those 4 columns :
id (autoincrement)
catid(int)
introtext(varchar)
ordering(int)
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 1 ║ 3024 ║ orange ║ 122 ║
║ 2 ║ 2024 ║ zebra ║ 45 ║
║ 3 ║ 3010 ║ juice ║ 55 ║
║ 4 ║ 3002 ║ build ║ 17 ║
║ 5 ║ 2003 ║ car ║ 87 ║
║ 6 ║ 1610 ║ other ║ 1521 ║
║ 7 ║ 1620 ║ other ║ 200 ║
╚════╩═══════╩═══════════╩══════════╝
I expect that
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 5 ║ 2003 ║ car ║ 1 ║
║ 4 ║ 3002 ║ build ║ 2 ║
║ 3 ║ 3010 ║ juice ║ 3 ║
║ 1 ║ 3024 ║ orange ║ 4 ║
║ 2 ║ 2024 ║ zebra ║ 5 ║
╚════╩═══════╩═══════════╩══════════╝
I want to
select * from biblek2_items where catid between 2001 and 3024
ORDER BY introtext ASC
- empty the ordering column
- reorder the ordering column by increment from 1 to n according to the result of the order column
I tried this with no success
DECLARE @variable int
SET @variable = 0
UPDATE `biblek2_items`
SET @variable = ordering = @variable + 1
WHERE ordering IN (SELECT ordering
FROM `biblek2_items`
WHERE catid BETWEEN 2001 AND 3024
ORDER BY `introtext` DESC)
I read in the forum that MySQL can't allow subrequests with ORDER BY, so could you help me
mysql
I have a table biblek2 items with those 4 columns :
id (autoincrement)
catid(int)
introtext(varchar)
ordering(int)
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 1 ║ 3024 ║ orange ║ 122 ║
║ 2 ║ 2024 ║ zebra ║ 45 ║
║ 3 ║ 3010 ║ juice ║ 55 ║
║ 4 ║ 3002 ║ build ║ 17 ║
║ 5 ║ 2003 ║ car ║ 87 ║
║ 6 ║ 1610 ║ other ║ 1521 ║
║ 7 ║ 1620 ║ other ║ 200 ║
╚════╩═══════╩═══════════╩══════════╝
I expect that
Table biblek2_items
╔════╦═══════╦═══════════╦══════════╗
║ ID ║ catid ║ introtext ║ ordering ║
╠════╬═══════╬═══════════╬══════════╣
║ 5 ║ 2003 ║ car ║ 1 ║
║ 4 ║ 3002 ║ build ║ 2 ║
║ 3 ║ 3010 ║ juice ║ 3 ║
║ 1 ║ 3024 ║ orange ║ 4 ║
║ 2 ║ 2024 ║ zebra ║ 5 ║
╚════╩═══════╩═══════════╩══════════╝
I want to
select * from biblek2_items where catid between 2001 and 3024
ORDER BY introtext ASC
- empty the ordering column
- reorder the ordering column by increment from 1 to n according to the result of the order column
I tried this with no success
DECLARE @variable int
SET @variable = 0
UPDATE `biblek2_items`
SET @variable = ordering = @variable + 1
WHERE ordering IN (SELECT ordering
FROM `biblek2_items`
WHERE catid BETWEEN 2001 AND 3024
ORDER BY `introtext` DESC)
I read in the forum that MySQL can't allow subrequests with ORDER BY, so could you help me
mysql
mysql
edited Mar 7 at 13:09
Thomas G
7,45871932
7,45871932
asked Mar 7 at 12:23
Jacques AbadaJacques Abada
1
1
the ORDER BY in the subquery makes no sense anyway, because, you don't LIMIT. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN in your main query.
– Thomas G
Mar 7 at 12:30
It looks like you mixed up the order of car and build in your results. Which MySQL version are you using?
– Thorsten Kettner
Mar 7 at 13:13
add a comment |
the ORDER BY in the subquery makes no sense anyway, because, you don't LIMIT. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN in your main query.
– Thomas G
Mar 7 at 12:30
It looks like you mixed up the order of car and build in your results. Which MySQL version are you using?
– Thorsten Kettner
Mar 7 at 13:13
the ORDER BY in the subquery makes no sense anyway, because, you don't LIMIT. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN in your main query.
– Thomas G
Mar 7 at 12:30
the ORDER BY in the subquery makes no sense anyway, because, you don't LIMIT. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN in your main query.
– Thomas G
Mar 7 at 12:30
It looks like you mixed up the order of car and build in your results. Which MySQL version are you using?
– Thorsten Kettner
Mar 7 at 13:13
It looks like you mixed up the order of car and build in your results. Which MySQL version are you using?
– Thorsten Kettner
Mar 7 at 13:13
add a comment |
1 Answer
1
active
oldest
votes
As explained in the comments :
The ORDER BY
in your sub query makes no sense anyway, because, you don't LIMIT
. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN
in your main query.
But there are other issues with your query.
Do this instead :
SET @row_number = 0 ;
UPDATE biblek2_items,
(select id, catid,introtext,ordering, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
) as temp
SET biblek2_items.ordering = temp.newordering
WHERE biblek2_items.ID = temp.ID
Additionally, if you have a large table, and a lot of users actively writing on it, to avoid inconsistencies or locking issues, I would suggest a slightly different method, using a temporary table to store the computed new ordering.
CREATE TABLE biblek2_items_TEMP (ID INT, ordering INT);
SET @row_number = 0 ;
INSERT INTO biblek2_items_TEMP
select id, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
;
UPDATE biblek2_items, biblek2_items_TEMP
SET biblek2_items.ordering = biblek2_items_TEMP.ordering
WHERE biblek2_items.ID = biblek2_items_TEMP.ID;
DROP TABLE biblek2_items_TEMP;
Tested successfully on MySQL 5.7 and MariaDB 10
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043710%2fmysql-update-column-with-subrequest-order-by%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As explained in the comments :
The ORDER BY
in your sub query makes no sense anyway, because, you don't LIMIT
. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN
in your main query.
But there are other issues with your query.
Do this instead :
SET @row_number = 0 ;
UPDATE biblek2_items,
(select id, catid,introtext,ordering, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
) as temp
SET biblek2_items.ordering = temp.newordering
WHERE biblek2_items.ID = temp.ID
Additionally, if you have a large table, and a lot of users actively writing on it, to avoid inconsistencies or locking issues, I would suggest a slightly different method, using a temporary table to store the computed new ordering.
CREATE TABLE biblek2_items_TEMP (ID INT, ordering INT);
SET @row_number = 0 ;
INSERT INTO biblek2_items_TEMP
select id, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
;
UPDATE biblek2_items, biblek2_items_TEMP
SET biblek2_items.ordering = biblek2_items_TEMP.ordering
WHERE biblek2_items.ID = biblek2_items_TEMP.ID;
DROP TABLE biblek2_items_TEMP;
Tested successfully on MySQL 5.7 and MariaDB 10
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
add a comment |
As explained in the comments :
The ORDER BY
in your sub query makes no sense anyway, because, you don't LIMIT
. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN
in your main query.
But there are other issues with your query.
Do this instead :
SET @row_number = 0 ;
UPDATE biblek2_items,
(select id, catid,introtext,ordering, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
) as temp
SET biblek2_items.ordering = temp.newordering
WHERE biblek2_items.ID = temp.ID
Additionally, if you have a large table, and a lot of users actively writing on it, to avoid inconsistencies or locking issues, I would suggest a slightly different method, using a temporary table to store the computed new ordering.
CREATE TABLE biblek2_items_TEMP (ID INT, ordering INT);
SET @row_number = 0 ;
INSERT INTO biblek2_items_TEMP
select id, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
;
UPDATE biblek2_items, biblek2_items_TEMP
SET biblek2_items.ordering = biblek2_items_TEMP.ordering
WHERE biblek2_items.ID = biblek2_items_TEMP.ID;
DROP TABLE biblek2_items_TEMP;
Tested successfully on MySQL 5.7 and MariaDB 10
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
add a comment |
As explained in the comments :
The ORDER BY
in your sub query makes no sense anyway, because, you don't LIMIT
. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN
in your main query.
But there are other issues with your query.
Do this instead :
SET @row_number = 0 ;
UPDATE biblek2_items,
(select id, catid,introtext,ordering, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
) as temp
SET biblek2_items.ordering = temp.newordering
WHERE biblek2_items.ID = temp.ID
Additionally, if you have a large table, and a lot of users actively writing on it, to avoid inconsistencies or locking issues, I would suggest a slightly different method, using a temporary table to store the computed new ordering.
CREATE TABLE biblek2_items_TEMP (ID INT, ordering INT);
SET @row_number = 0 ;
INSERT INTO biblek2_items_TEMP
select id, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
;
UPDATE biblek2_items, biblek2_items_TEMP
SET biblek2_items.ordering = biblek2_items_TEMP.ordering
WHERE biblek2_items.ID = biblek2_items_TEMP.ID;
DROP TABLE biblek2_items_TEMP;
Tested successfully on MySQL 5.7 and MariaDB 10
As explained in the comments :
The ORDER BY
in your sub query makes no sense anyway, because, you don't LIMIT
. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN
in your main query.
But there are other issues with your query.
Do this instead :
SET @row_number = 0 ;
UPDATE biblek2_items,
(select id, catid,introtext,ordering, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
) as temp
SET biblek2_items.ordering = temp.newordering
WHERE biblek2_items.ID = temp.ID
Additionally, if you have a large table, and a lot of users actively writing on it, to avoid inconsistencies or locking issues, I would suggest a slightly different method, using a temporary table to store the computed new ordering.
CREATE TABLE biblek2_items_TEMP (ID INT, ordering INT);
SET @row_number = 0 ;
INSERT INTO biblek2_items_TEMP
select id, (@row_number:=@row_number + 1) AS newordering
from biblek2_items
where catid between 2001 and 3024
ORDER BY introtext ASC
;
UPDATE biblek2_items, biblek2_items_TEMP
SET biblek2_items.ordering = biblek2_items_TEMP.ordering
WHERE biblek2_items.ID = biblek2_items_TEMP.ID;
DROP TABLE biblek2_items_TEMP;
Tested successfully on MySQL 5.7 and MariaDB 10
edited Mar 7 at 13:44
answered Mar 7 at 13:38
Thomas GThomas G
7,45871932
7,45871932
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
add a comment |
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
Hello my friend thank you very much, the result is perfect, i will keep your method with temporary table, very helpfull
– Jacques Abada
Mar 7 at 15:22
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
@JacquesAbada cool! now, if this answers the question you should do your SO duties, and mark it as answered (and when you find an answer really helpful you can also add a +1 ;)
– Thomas G
Mar 7 at 15:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043710%2fmysql-update-column-with-subrequest-order-by%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
the ORDER BY in the subquery makes no sense anyway, because, you don't LIMIT. So all rows will be returned and it doesn't matter how they are ordered because all of them are taken into account with the IN in your main query.
– Thomas G
Mar 7 at 12:30
It looks like you mixed up the order of car and build in your results. Which MySQL version are you using?
– Thorsten Kettner
Mar 7 at 13:13