MySQL Forums
Forum List  »  Newbie

NestedSQL?
Posted by: Nick Abelson
Date: April 07, 2021 04:41AM

Hi
I am getting confused by how to write a query and hoping someone can help.

I want to query a subset of data. I think the first thing to do is to create a dataset based on the following query:

Select
contents.Content_ID,
contents.ContentTitle,
contents.ContentBody,
user_behaviour.userid,
user_behaviour.behaviourtypeid
From
content_behaviours Right Outer Join
contents On content_behaviours.content_id = contents.Content_ID Inner Join
user_behaviour On content_behaviours.behaviourtype_id = user_behaviour.behaviourtypeid
Where
user_behaviour.userid = 294

I then want to query that data with the following:

Select Distinct
contents1.ContentBody

From
userhabits Inner Join
users On users.User_ID = userhabits.user_id Inner Join
content_habitparameter On content_habitparameter.Habit_ID = userhabits.habit_id Inner Join
contents On content_habitparameter.Content_ID = contents.Content_ID,
contents contents1
Where
((((userhabits.habit_id = content_habitparameter.Habit_ID And
(userhabits.amount <= content_habitparameter.Max_Value Or
userhabits.amount <= content_habitparameter.Max_Value Or
userhabits.yesorno = content_habitparameter.yesorno)

I think I need to do a nested statement (although I have read these aren't very efficient). Unfortunately I can't work out how to do it and would welcome some help.

thanks in advance

Options: ReplyQuote


Subject
Written By
Posted
NestedSQL?
April 07, 2021 04:41AM
April 07, 2021 08:42AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.