473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Stumped. Totally... (but there must be a way!?)

Hi there...

I am having a whole bunch of trouble trying to design a certain query. I
have two tables (see a representation of them here:
http://www.plankmeister.org.uk/tables.html ) one called menu_data and one
called page_data.

menu_data contains a list of defined menus (menu_group) which may be sorted
according to the menu_group_display_order column.

page_data contains a list of page definitions. Each page belongs to a
menu_group. All the pages in a given group may be sorted according to the
page_display_order column. (for instance, a query to order all pages with a
menu_group equal to 1 in ascending order would produce:
Cats
Dogs
Fish
Squirrels)

What I am trying to do is to design a query that will tell me the
page_user_name of all the pages that sit at the 'top' of their menu group,
but ordered by the menu_group_display_order column.
So basically, it will order the data in menu_data by the
menu_group_display_order colum, then comparing menu_data.menu_group to
page_data.menu_group, will return the 'first' row after being ordered by
page_display_order, so that in the case of the data given, the return would
be:

Horses
Cats
Birds
Rabbits
I've tried UNION, GROUP BY, TOP 1, INNER JOIN, OUTER JOIN, SLIGHTLY TO THE
LEFT JOIN, ONLY IF ITS A WEDNESDAY JOIN... etc etc... But I just can't get
it to work! It either returns 40 rows, or one. I've spent a total of about
10 hours trying to design this query, and am losing what precious little
hair I have left at an alarming rate.

Hope someone can provide some insight!

Plankmeister.

Jul 20 '05 #1
3 1206
You could try this:

SELECT page_user_name
FROM page_data pd
INNER JOIN menu_data md ON pd.menu_group = md.menu_group AND
pd.page_display_order = 1
ORDER BY md.menu_group_dispaly_order
Hope it helps

"The Plankmeister" <pl******************@hotmail.com> wrote in message
news:40***********************@dread16.news.tele.d k...
Hi there...

I am having a whole bunch of trouble trying to design a certain query. I
have two tables (see a representation of them here:
http://www.plankmeister.org.uk/tables.html ) one called menu_data and one
called page_data.

menu_data contains a list of defined menus (menu_group) which may be sorted according to the menu_group_display_order column.

page_data contains a list of page definitions. Each page belongs to a
menu_group. All the pages in a given group may be sorted according to the
page_display_order column. (for instance, a query to order all pages with a menu_group equal to 1 in ascending order would produce:
Cats
Dogs
Fish
Squirrels)

What I am trying to do is to design a query that will tell me the
page_user_name of all the pages that sit at the 'top' of their menu group,
but ordered by the menu_group_display_order column.
So basically, it will order the data in menu_data by the
menu_group_display_order colum, then comparing menu_data.menu_group to
page_data.menu_group, will return the 'first' row after being ordered by
page_display_order, so that in the case of the data given, the return would be:

Horses
Cats
Birds
Rabbits
I've tried UNION, GROUP BY, TOP 1, INNER JOIN, OUTER JOIN, SLIGHTLY TO THE
LEFT JOIN, ONLY IF ITS A WEDNESDAY JOIN... etc etc... But I just can't get
it to work! It either returns 40 rows, or one. I've spent a total of about
10 hours trying to design this query, and am losing what precious little
hair I have left at an alarming rate.

Hope someone can provide some insight!

Plankmeister.

Jul 20 '05 #2

"Igor Raytsin" <n&*@cyberus.ca> wrote in message
news:40********@news.cybersurf.net...
You could try this:

SELECT page_user_name
FROM page_data pd
INNER JOIN menu_data md ON pd.menu_group = md.menu_group AND
pd.page_display_order = 1
ORDER BY md.menu_group_dispaly_order
Hope it helps
Indeed it does... Many thanks! However... a further complication is that the
lowest value in page_display_order doesn't always = 1. It could be 0, or
higher in certain circumstances.

"The Plankmeister" <pl******************@hotmail.com> wrote in message
news:40***********************@dread16.news.tele.d k...
Hi there...

I am having a whole bunch of trouble trying to design a certain query. I
have two tables (see a representation of them here:
http://www.plankmeister.org.uk/tables.html ) one called menu_data and one called page_data.

menu_data contains a list of defined menus (menu_group) which may be sorted
according to the menu_group_display_order column.

page_data contains a list of page definitions. Each page belongs to a
menu_group. All the pages in a given group may be sorted according to the page_display_order column. (for instance, a query to order all pages with a
menu_group equal to 1 in ascending order would produce:
Cats
Dogs
Fish
Squirrels)

What I am trying to do is to design a query that will tell me the
page_user_name of all the pages that sit at the 'top' of their menu

group, but ordered by the menu_group_display_order column.
So basically, it will order the data in menu_data by the
menu_group_display_order colum, then comparing menu_data.menu_group to
page_data.menu_group, will return the 'first' row after being ordered by
page_display_order, so that in the case of the data given, the return

would
be:

Horses
Cats
Birds
Rabbits
I've tried UNION, GROUP BY, TOP 1, INNER JOIN, OUTER JOIN, SLIGHTLY TO THE LEFT JOIN, ONLY IF ITS A WEDNESDAY JOIN... etc etc... But I just can't get it to work! It either returns 40 rows, or one. I've spent a total of about 10 hours trying to design this query, and am losing what precious little
hair I have left at an alarming rate.

Hope someone can provide some insight!

Plankmeister.


Jul 20 '05 #3
Then it will look like this.

SELECT md.menu_group_display_order, pd1.page_user_name
FROM page_data pd1
INNER JOIN
(SELECT menu_group, MIN(page_display_order) min_page_display_order
FROM page_data
GROUP BY menu_group) pd2
ON pd1.menu_group = pd2.menu_group AND pd1.page_display_order =
pd2.min_page_display_order
INNER JOIN menu_data md ON pd1.menu_group = md.menu_group
ORDER BY md.menu_group_display_order
"The Plankmeister" <pl******************@hotmail.com> wrote in message
news:40***********************@dread16.news.tele.d k...

"Igor Raytsin" <n&*@cyberus.ca> wrote in message
news:40********@news.cybersurf.net...
You could try this:

SELECT page_user_name
FROM page_data pd
INNER JOIN menu_data md ON pd.menu_group = md.menu_group AND
pd.page_display_order = 1
ORDER BY md.menu_group_dispaly_order
Hope it helps
Indeed it does... Many thanks! However... a further complication is that

the lowest value in page_display_order doesn't always = 1. It could be 0, or
higher in certain circumstances.

"The Plankmeister" <pl******************@hotmail.com> wrote in message
news:40***********************@dread16.news.tele.d k...
Hi there...

I am having a whole bunch of trouble trying to design a certain query. I have two tables (see a representation of them here:
http://www.plankmeister.org.uk/tables.html ) one called menu_data and one called page_data.

menu_data contains a list of defined menus (menu_group) which may be

sorted
according to the menu_group_display_order column.

page_data contains a list of page definitions. Each page belongs to a
menu_group. All the pages in a given group may be sorted according to the page_display_order column. (for instance, a query to order all pages with
a
menu_group equal to 1 in ascending order would produce:
Cats
Dogs
Fish
Squirrels)

What I am trying to do is to design a query that will tell me the
page_user_name of all the pages that sit at the 'top' of their menu

group, but ordered by the menu_group_display_order column.
So basically, it will order the data in menu_data by the
menu_group_display_order colum, then comparing menu_data.menu_group to
page_data.menu_group, will return the 'first' row after being ordered by page_display_order, so that in the case of the data given, the return

would
be:

Horses
Cats
Birds
Rabbits
I've tried UNION, GROUP BY, TOP 1, INNER JOIN, OUTER JOIN, SLIGHTLY TO THE LEFT JOIN, ONLY IF ITS A WEDNESDAY JOIN... etc etc... But I just can't get it to work! It either returns 40 rows, or one. I've spent a total of about 10 hours trying to design this query, and am losing what precious little hair I have left at an alarming rate.

Hope someone can provide some insight!

Plankmeister.



Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Graham Nicholls | last post by:
Hi. I'm having some fun with numbers. I've extraced an image sizes from a jpeg file img_x,img_y=image.getsize() then I'm trying to use those sizes to scale the image, but because python...
7
by: Sonny | last post by:
I need to port a library that is written entirely in C to C++. The library is supported on quite a few platforms (windows, Solaris, Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing...
12
by: code_wrong | last post by:
Hi, as the subject says How many browsers must we support? How many are there exactly? When I run this JavaScript in Firefox and IE6: function init(){ if(document.getElementById) alert("W3C...
2
by: ViperDK | last post by:
What is the best way for that? I store all Data in the original form in the Database. To prevent output fields (especially the fields everyone can use) to do bad things like killing the...
1
by: Adjo | last post by:
Okay, I've seen all the examples of using comboboxes on webforms when using simple values. And in the issue-tracker starterkit there is a way to use comboboxes with id/value foreign keys in a smart...
15
by: UrsusMaximus | last post by:
While preparing a Python411 podcast about classes and OOP, my mind wondered far afield. I found myself constructing an extended metaphor or analogy between the way programs are organized and...
10
by: Frederick Gotham | last post by:
Irrespective of whether NDEBUG is defined, must an assertion expression always be evaluated? For instance, is the following code perfectly OK? #define NDEBUG #include <assert.h> int...
4
by: superflit | last post by:
Hi All, I am reading a log file, and wondering what is the best way to read and analize this. I am think in two options: 1- Read the data and put all variables in a list 2- Read the data and...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.