mysql using subquery with no join
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
here are the relevant tables
movie(id, title, relYear, category, runTime, director,
studioName, description, rating)
actor(aID, fName, surname, gender)
stars(movieID, actorID)
movGenre(movieID, genre)
I'm just trying to return movies where 'Michael Fassbender' stars using a subquery ... 'id' in movie refers to the the movie id not the actor id if that was the case I could do
SELECT title, category
FROM movie
WHERE 'id' =(SELECT 'aID'
FROM actor
WHERE fName='Michael' and surname='Fassbender')
Is there a way to do it without using any joins?
mysql join subquery
add a comment |
here are the relevant tables
movie(id, title, relYear, category, runTime, director,
studioName, description, rating)
actor(aID, fName, surname, gender)
stars(movieID, actorID)
movGenre(movieID, genre)
I'm just trying to return movies where 'Michael Fassbender' stars using a subquery ... 'id' in movie refers to the the movie id not the actor id if that was the case I could do
SELECT title, category
FROM movie
WHERE 'id' =(SELECT 'aID'
FROM actor
WHERE fName='Michael' and surname='Fassbender')
Is there a way to do it without using any joins?
mysql join subquery
2
Yes, there are some way to do it withoutJOIN
s but why? There are even ways to do it without MySQL, but why?
– Alex
Nov 22 '18 at 18:04
add a comment |
here are the relevant tables
movie(id, title, relYear, category, runTime, director,
studioName, description, rating)
actor(aID, fName, surname, gender)
stars(movieID, actorID)
movGenre(movieID, genre)
I'm just trying to return movies where 'Michael Fassbender' stars using a subquery ... 'id' in movie refers to the the movie id not the actor id if that was the case I could do
SELECT title, category
FROM movie
WHERE 'id' =(SELECT 'aID'
FROM actor
WHERE fName='Michael' and surname='Fassbender')
Is there a way to do it without using any joins?
mysql join subquery
here are the relevant tables
movie(id, title, relYear, category, runTime, director,
studioName, description, rating)
actor(aID, fName, surname, gender)
stars(movieID, actorID)
movGenre(movieID, genre)
I'm just trying to return movies where 'Michael Fassbender' stars using a subquery ... 'id' in movie refers to the the movie id not the actor id if that was the case I could do
SELECT title, category
FROM movie
WHERE 'id' =(SELECT 'aID'
FROM actor
WHERE fName='Michael' and surname='Fassbender')
Is there a way to do it without using any joins?
mysql join subquery
mysql join subquery
edited Nov 22 '18 at 17:42
Chowkidar Madhur Bhaiya
19.8k62336
19.8k62336
asked Nov 22 '18 at 17:41
JadeJade
145
145
2
Yes, there are some way to do it withoutJOIN
s but why? There are even ways to do it without MySQL, but why?
– Alex
Nov 22 '18 at 18:04
add a comment |
2
Yes, there are some way to do it withoutJOIN
s but why? There are even ways to do it without MySQL, but why?
– Alex
Nov 22 '18 at 18:04
2
2
Yes, there are some way to do it without
JOIN
s but why? There are even ways to do it without MySQL, but why?– Alex
Nov 22 '18 at 18:04
Yes, there are some way to do it without
JOIN
s but why? There are even ways to do it without MySQL, but why?– Alex
Nov 22 '18 at 18:04
add a comment |
2 Answers
2
active
oldest
votes
You can utilize Correlated Subquery with Exists()
SELECT m.title, m.category
FROM movie AS m
WHERE EXISTS (SELECT 1
FROM stars AS s
JOIN actor AS a ON a.aID = s.actorID
WHERE a.fName = 'Michael' AND
a.surname = 'Fassbender' AND
s.movieID = m.id)
Above solution still utilize JOIN
in some way (inside the subquery). A solution utilizing no Join at all can be:
SELECT title, category
FROM movie
WHERE id IN (SELECT movieID
FROM stars
WHERE actorID IN (SELECT aID
FROM actor
WHERE fName = 'Michael' AND
surname = 'Fassbender'))
P.S. Unless this is some trick assignment/HW, I would seriously recommend against using this query in a real-life application.
add a comment |
SELECT DISTINCT m.title, m.category
FROM movie
INNER JOIN stars s
ON s.movieID = m.id
INNER JOIN actors a
ON s.actorID = a.aID
AND a.fName='Michael'
AND a.surname='Fassbender'
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
:-) @MadhurBhaiya Do you really believe that your solution has noJOIN
s? do Ctrl+F ;-) You will be surprised. :-)
– Alex
Nov 22 '18 at 17:59
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
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%2f53436011%2fmysql-using-subquery-with-no-join%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can utilize Correlated Subquery with Exists()
SELECT m.title, m.category
FROM movie AS m
WHERE EXISTS (SELECT 1
FROM stars AS s
JOIN actor AS a ON a.aID = s.actorID
WHERE a.fName = 'Michael' AND
a.surname = 'Fassbender' AND
s.movieID = m.id)
Above solution still utilize JOIN
in some way (inside the subquery). A solution utilizing no Join at all can be:
SELECT title, category
FROM movie
WHERE id IN (SELECT movieID
FROM stars
WHERE actorID IN (SELECT aID
FROM actor
WHERE fName = 'Michael' AND
surname = 'Fassbender'))
P.S. Unless this is some trick assignment/HW, I would seriously recommend against using this query in a real-life application.
add a comment |
You can utilize Correlated Subquery with Exists()
SELECT m.title, m.category
FROM movie AS m
WHERE EXISTS (SELECT 1
FROM stars AS s
JOIN actor AS a ON a.aID = s.actorID
WHERE a.fName = 'Michael' AND
a.surname = 'Fassbender' AND
s.movieID = m.id)
Above solution still utilize JOIN
in some way (inside the subquery). A solution utilizing no Join at all can be:
SELECT title, category
FROM movie
WHERE id IN (SELECT movieID
FROM stars
WHERE actorID IN (SELECT aID
FROM actor
WHERE fName = 'Michael' AND
surname = 'Fassbender'))
P.S. Unless this is some trick assignment/HW, I would seriously recommend against using this query in a real-life application.
add a comment |
You can utilize Correlated Subquery with Exists()
SELECT m.title, m.category
FROM movie AS m
WHERE EXISTS (SELECT 1
FROM stars AS s
JOIN actor AS a ON a.aID = s.actorID
WHERE a.fName = 'Michael' AND
a.surname = 'Fassbender' AND
s.movieID = m.id)
Above solution still utilize JOIN
in some way (inside the subquery). A solution utilizing no Join at all can be:
SELECT title, category
FROM movie
WHERE id IN (SELECT movieID
FROM stars
WHERE actorID IN (SELECT aID
FROM actor
WHERE fName = 'Michael' AND
surname = 'Fassbender'))
P.S. Unless this is some trick assignment/HW, I would seriously recommend against using this query in a real-life application.
You can utilize Correlated Subquery with Exists()
SELECT m.title, m.category
FROM movie AS m
WHERE EXISTS (SELECT 1
FROM stars AS s
JOIN actor AS a ON a.aID = s.actorID
WHERE a.fName = 'Michael' AND
a.surname = 'Fassbender' AND
s.movieID = m.id)
Above solution still utilize JOIN
in some way (inside the subquery). A solution utilizing no Join at all can be:
SELECT title, category
FROM movie
WHERE id IN (SELECT movieID
FROM stars
WHERE actorID IN (SELECT aID
FROM actor
WHERE fName = 'Michael' AND
surname = 'Fassbender'))
P.S. Unless this is some trick assignment/HW, I would seriously recommend against using this query in a real-life application.
edited Nov 22 '18 at 17:59
answered Nov 22 '18 at 17:45
Chowkidar Madhur BhaiyaChowkidar Madhur Bhaiya
19.8k62336
19.8k62336
add a comment |
add a comment |
SELECT DISTINCT m.title, m.category
FROM movie
INNER JOIN stars s
ON s.movieID = m.id
INNER JOIN actors a
ON s.actorID = a.aID
AND a.fName='Michael'
AND a.surname='Fassbender'
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
:-) @MadhurBhaiya Do you really believe that your solution has noJOIN
s? do Ctrl+F ;-) You will be surprised. :-)
– Alex
Nov 22 '18 at 17:59
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
add a comment |
SELECT DISTINCT m.title, m.category
FROM movie
INNER JOIN stars s
ON s.movieID = m.id
INNER JOIN actors a
ON s.actorID = a.aID
AND a.fName='Michael'
AND a.surname='Fassbender'
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
:-) @MadhurBhaiya Do you really believe that your solution has noJOIN
s? do Ctrl+F ;-) You will be surprised. :-)
– Alex
Nov 22 '18 at 17:59
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
add a comment |
SELECT DISTINCT m.title, m.category
FROM movie
INNER JOIN stars s
ON s.movieID = m.id
INNER JOIN actors a
ON s.actorID = a.aID
AND a.fName='Michael'
AND a.surname='Fassbender'
SELECT DISTINCT m.title, m.category
FROM movie
INNER JOIN stars s
ON s.movieID = m.id
INNER JOIN actors a
ON s.actorID = a.aID
AND a.fName='Michael'
AND a.surname='Fassbender'
answered Nov 22 '18 at 17:50
AlexAlex
15.3k12039
15.3k12039
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
:-) @MadhurBhaiya Do you really believe that your solution has noJOIN
s? do Ctrl+F ;-) You will be surprised. :-)
– Alex
Nov 22 '18 at 17:59
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
add a comment |
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
:-) @MadhurBhaiya Do you really believe that your solution has noJOIN
s? do Ctrl+F ;-) You will be surprised. :-)
– Alex
Nov 22 '18 at 17:59
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
OP asking for solution without joins :-) "Is there a way to do it without using any joins?"
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 17:52
:-) @MadhurBhaiya Do you really believe that your solution has no
JOIN
s? do Ctrl+F ;-) You will be surprised. :-)– Alex
Nov 22 '18 at 17:59
:-) @MadhurBhaiya Do you really believe that your solution has no
JOIN
s? do Ctrl+F ;-) You will be surprised. :-)– Alex
Nov 22 '18 at 17:59
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
I know. check the latest update. Do Ctrl + F5 :D
– Chowkidar Madhur Bhaiya
Nov 22 '18 at 18:00
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%2f53436011%2fmysql-using-subquery-with-no-join%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
2
Yes, there are some way to do it without
JOIN
s but why? There are even ways to do it without MySQL, but why?– Alex
Nov 22 '18 at 18:04