update student s set school_year_id = (select distinct s.id from
school_year s, interns i where lower(s.school_year_name) =
lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id);
ERROR 1242 (21000): Subquery returns more than 1 row
I am trying to replace a column in interns.student.school_year_id to
read an ID from the school_year table, where school_year_name will map
to interns.interns.enrollment_year
I can't for the life of me figure this one out, please help!
Thanx
Phil 6 34900 ph**************@gmail.com wrote: update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id); ERROR 1242 (21000): Subquery returns more than 1 row
I am trying to replace a column in interns.student.school_year_id to read an ID from the school_year table, where school_year_name will map to interns.interns.enrollment_year
I can't for the life of me figure this one out, please help!
Thanx Phil
can you post the definition of the tables in question?
noone wrote: ph**************@gmail.com wrote: update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id); ERROR 1242 (21000): Subquery returns more than 1 row
I am trying to replace a column in interns.student.school_year_id to read an ID from the school_year table, where school_year_name will map to interns.interns.enrollment_year
I can't for the life of me figure this one out, please help!
Thanx Phil
can you post the definition of the tables in question?
table students:
id int not null auto_increment, primary key (id),
school_year_id int not null,
unique_key varchar(16) not null
table interns:
id int not null auto_increment, primary key (id),
enrollment_year varchar(80),
unique_key varchar(16) not null
table school_year:
id int not null auto_increment, primary key (id),
school_year_name varchar(50) not null
That's unfortunately all I'm allowed to give you, cannot give full
table definitions, we're not allowed here.
Phil
<ph**************@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com... update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id); ERROR 1242 (21000): Subquery returns more than 1 row
Use IN instead of = when you need to match multiple values returned from the
subquery.
For example:
update student set school_year_id IN (select distinct s.id from
school_year s, interns i where lower(s.school_year_name) =
lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id);
Also, using the same table alias "s" in both the update and the subquery is
confusing. You don't need the table alias in the update, so I removed it in
the example above.
Regards,
Bill K.
Bill Karwin wrote: <ph**************@gmail.com> wrote in message news:11**********************@i40g2000cwc.googlegr oups.com... update student s set school_year_id = (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id); ERROR 1242 (21000): Subquery returns more than 1 row Use IN instead of = when you need to match multiple values returned from the subquery.
I'm sorry but apparently I can't do that in MySQL 4.1.12:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'IN (
SELECT DISTINCT q.id FROM interns.student_school_enrollment_status q,
inte' at line 1
USING
update student s
set school_year_id IN (
SELECT DISTINCT q.id FROM interns.student_school_enrollment_status q,
interns.interns i
WHERE lower(q.student_school_enrollment_status_name) =
lower(i.enrollment_status)
AND s.unique_key = i.unique_key
)
Phil For example:
update student set school_year_id IN (select distinct s.id from school_year s, interns i where lower(s.school_year_name) = lower(i.enrollment_year)and s.unique_key = i.unique_key group by s.id);
Also, using the same table alias "s" in both the update and the subquery is confusing. You don't need the table alias in the update, so I removed it in the example above.
Regards, Bill K.
<ph**************@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com... Use IN instead of = when you need to match multiple values returned from the subquery.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( SELECT DISTINCT q.id FROM interns.student_school_enrollment_status q, inte' at line 1
D'ohh! I'm sorry, my mistake. I wasn't looking closely, and didn't notice
this was in the context of an update assignment, not an equals comparison.
I can't tell what you're trying to do in the update. I suspect your logic
has become muddled. Are you trying to do a multi-table update?
Regards,
Bill K.
Bill Karwin wrote: <ph**************@gmail.com> wrote in message news:11**********************@i40g2000cwc.googlegr oups.com... Use IN instead of = when you need to match multiple values returned from the subquery. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( SELECT DISTINCT q.id FROM interns.student_school_enrollment_status q, inte' at line 1
D'ohh! I'm sorry, my mistake. I wasn't looking closely, and didn't notice this was in the context of an update assignment, not an equals comparison.
I can't tell what you're trying to do in the update. I suspect your logic has become muddled. Are you trying to do a multi-table update?
Yes, and someone else on mysqlfreaks.com came up with it, it was so
easy!
update student s, interns i, school_year y set s.school_year_id = y.id
where s.unique_key = i.unique_key and lower(i.enrollment_status) =
lower(y.school_year_name)
Phil Regards, Bill K. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: leegold2 |
last post by:
I tried what's below, seemed OK, so I replaced an "IN" for the "=" in
the subquery below because of the subquery's error message. I thought
w/"IN" I'd get three (3) records returned as expected....
|
by: edself |
last post by:
Greetings,
I am semi-new to Access and have a query question. I presume the solution
is easy, but need some help.
I have created a database with a Contact table. The contact table contains...
|
by: Rod |
last post by:
I have a client site where the code below has been working happily for at
least four months. The site is using SQL Server 7. The code is ASP.NET
Last week an error appeared related to the...
|
by: Edwin Pauli |
last post by:
Hi,
Yesterday i had upgrade my PostgreSQL server from version 7.2.4
to 7.4.1.
There are troubles with a subquery after the upgrade.
Here is the query:
SELECT team_naam, team_id, wpim, (
|
by: Dan Amodeo |
last post by:
I am using DB2 (version 7, soon to be updated to 8) on a mainframe that runs Z/OS.
It seems to me that the following query is legitimate, but I get an error message.
(This is not a real query; I'm...
|
by: abbaskhan |
last post by:
Actuall in this query i am trying to to compare the monthly change percentage
i ,e january 2007 aganest dec 2006 and the value is available in one table
and same column one below the other
when...
|
by: ThePrinceIsRight |
last post by:
I have a problem with using a subquery in MS Access. The purpose of the sub-query is to create a list of people who have had doctor exams in the past 6 months and exclude them from the main query....
|
by: arunmen |
last post by:
Hi folks,
I have an situation like I have an table named Location where by it stores all
the details of location. In the table I have 2 columns State, city where by I have some duplicate values...
|
by: jideesh |
last post by:
---------------trigger code
create trigger DeletepurchaseItems on table_purchaseitems
for delete,update
as
begin
select * from deleted
update table_STOCK set ostock=(ostock-(select sqty from...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
| |