Hi! I have been asked to sort a table into a patricular order to be used with a mail merge, however, I have no idea where to start with the query!
The table currently consists of Schoolname, Address, Subject.
Single schools can have multiple subjects. For example, - SELECT * WHERE schoolname='The Streetly School'
, may return 4 rows, all the same except for the 'Subject' column, which could contain 'Mathematics', 'English', 'Science', and another 'Mathematics' - for good measure.
Now for the query:
I want to sort the table by schools, based on what subjects they have.
For instance, I want the address of a school that has english maths and science, but does not have art, is this possible?
I've tried - WHERE subject='mathematics'
-
OR WHERE subject='English'
-
OR WHERE subject='science'
But of course it gets all schools that have EITHER of those subjects, not schools that have all 3 subjects.
Thanks for your time in reading this essay!
7 1516
Can you place the table structure of the table and why you have used 3 WHERE command in the query?
Subash :)
Hi! I have been asked to sort a table into a patricular order to be used with a mail merge, however, I have no idea where to start with the query!
The table currently consists of Schoolname, Address, Subject.
Single schools can have multiple subjects. For example, - SELECT * WHERE schoolname='The Streetly School'
, may return 4 rows, all the same except for the 'Subject' column, which could contain 'Mathematics', 'English', 'Science', and another 'Mathematics' - for good measure.
Now for the query:
I want to sort the table by schools, based on what subjects they have.
For instance, I want the address of a school that has english maths and science, but does not have art, is this possible?
I've tried - WHERE subject='mathematics'
-
OR WHERE subject='English'
-
OR WHERE subject='science'
But of course it gets all schools that have EITHER of those subjects, not schools that have all 3 subjects.
Thanks for your time in reading this essay!
Since you have only 1 column for the subject, how do you want to select on the existence of 4 different values? That is impossible, unless you have all these values ('mathematics', 'English', 'science' and 'art') stored in one string in one column with name 'subject' (like column content ='mathematics, science, art, English'). Do you?
Ronald :cool:
For each criteria, you'll have to add the table in the FROM clause
for example, the your mats, eng , science query: -
-
select a.schoolname
-
from school a, school b, school c
-
where
-
a.schoolname = b.schoolname
-
and a.schoolname=c.schoolname
-
and a.subject = 'mathematics'
-
and b.subject = 'english'
-
and c.subject = 'science'
-
-
Hi guys, I think ronverdonk hit the nail on the head... They come up as individual rows, so this method may be impossible. Is there anyway of having the first record appear, then additional columns show up on the same row?
Allow me to explain....
I have one table called 'orders'. Orders is pretty awesome, It holds the name and address, the unique key is the 'OrderEntryId' column.
I have another table called 'productorders', this has the individual products ordered in one order on seperate rows. It's unique key is the 'ProductOrderEntryId' although it does contain the same 'OrderEntryId' column that corresponds to the order.
So 'orders' looks like this: - OrderEntryId | School Name | Address |
-
-
1211 The School England
'productsorders' looks like this - ProductOrderEntryId | OrderEntryId | Subject |
-
-
234 1211 English
-
235 1211 Maths
-
236 1211 Science
Could I do some sort of join that will make my table look like this: - SELECT orders.orderentryid, orders.schoolname, orders.address, productorders.subject#1, products.subject#2, products.subject#3, products.subject#n
-
SOME JOIN COMMAND
-
WHERE orders.orderentryid='1211' ;
-
-
OrderEntryId | School Name | Address | Subject#1 | Subject#2 | subject#3|
-
1211 The School England English Maths Science
Effectively making rows into additional columns?
I found THIS, but as I don't have an equivelent to the 'location'... Couldn't figure out how to implement it.
Any more help guys???
THANKS TO EVERYONE WHO'S REPLIED SO FAR!! I REALLY DO APPRECIATE YOUR TIME AND EFFORT!
Hi!. didn't you check my post at no: 4. Do you have any problem running it?
Hi guys, I think ronverdonk hit the nail on the head... They come up as individual rows, so this method may be impossible. Is there anyway of having the first record appear, then additional columns show up on the same row?
Allow me to explain....
I have one table called 'orders'. Orders is pretty awesome, It holds the name and address, the unique key is the 'OrderEntryId' column.
I have another table called 'productorders', this has the individual products ordered in one order on seperate rows. It's unique key is the 'ProductOrderEntryId' although it does contain the same 'OrderEntryId' column that corresponds to the order.
So 'orders' looks like this: - OrderEntryId | School Name | Address |
-
-
1211 The School England
'productsorders' looks like this - ProductOrderEntryId | OrderEntryId | Subject |
-
-
234 1211 English
-
235 1211 Maths
-
236 1211 Science
Could I do some sort of join that will make my table look like this: - SELECT orders.orderentryid, orders.schoolname, orders.address, productorders.subject#1, products.subject#2, products.subject#3, products.subject#n
-
SOME JOIN COMMAND
-
WHERE orders.orderentryid='1211' ;
-
-
OrderEntryId | School Name | Address | Subject#1 | Subject#2 | subject#3|
-
1211 The School England English Maths Science
Effectively making rows into additional columns?
I found THIS, but as I don't have an equivelent to the 'location'... Couldn't figure out how to implement it.
Any more help guys???
THANKS TO EVERYONE WHO'S REPLIED SO FAR!! I REALLY DO APPRECIATE YOUR TIME AND EFFORT!
Hellooo
I don't know if I understand it.
There aren't seperate tables for schools, or for subjects.
Hellooo
I don't know if I understand it.
There aren't seperate tables for schools, or for subjects.
WXY run the query I gave at post #4 and see what it gives.
There is only 1 table, which I call 3 times in the query using different alias. This has the same effect as if I was calling 3 different tables.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris |
last post by:
Hello all-
Fairly new to SQL and I need to issue a pretty complex query (complex
being a relative term here :) ).
To dumb down my example for display purposes, I have two tables in my
schema...
|
by: jqq |
last post by:
SQL2K on W2Kserver
I need some help revamping a rather complicated query. I've given the
table and existing query information below. (FYI, changing the
database structure is right out.)
The...
|
by: Norma |
last post by:
I am trying to make a query pull data from between the dates I enter
in the parameter but also look back 'in time' to see where 2 other
fields have null values, and only pull data into the query if...
|
by: d.p. |
last post by:
I need to create a conditional expression that's not a simple one.
I need the expression to be in the field of a table, that depends on another
field (different column) in that same table. It...
|
by: Jeff |
last post by:
Ok gang. Here is something complicated, well, at least to me anyway.
Using Access DB
I have a table in my DB called members. In that table, I have 2 tables I
will be using "username" and...
|
by: Matthew Crouch |
last post by:
i suck so much that i don't even know if this is a JOIN or a subquery or
who-knows what. Here's the idea:
I want to select two things at the same time (form one table)
average for columnX
and...
|
by: norm10115 |
last post by:
I have a single MySQL table named "monthly" that contains the following fields:
Id, Name, Interface, Status, MonYear
I want to query "Status" for the past 3 months, of each "Device" and...
|
by: Nick |
last post by:
Hi,
I have two tables Trade table and Cons table. Records are inserted in
both the tables independent of each other. There are fields like
Exc_Ref, Qty, Date in both the tables.
I need to...
|
by: MarkNeumann |
last post by:
I'm coming from a Corel paradox background and moving into an Access environment. So I'm struggling with something that I think is probably way simpler than I'm making it out to be.
Access 2007...
|
by: jonceramic |
last post by:
Hi All,
I need to know the best way to set up a datawarehouse/materialized
view for doing statistics/graphs in Access. My crosstabs and unions
are getting too complicated to crunch in real...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |