Replacing multiple columns with query from another

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your SQLite question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your SQLite question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

srl309
Programmer
i dont know why the joins aren't working it looks like they are cross joins and thats why they are returning 3 values you can probably do it like below: [code] select * from presentation_schedule WHERE problem_set IN(select person_id from members) OR literature IN(select person_id from members) OR research IN(select person_id from members); UPDATE presentation_schedule SET problem_set = (SELECT name FROM members WHERE members.person_id = presentation_schedule.problem_set), literature = (SELECT name FROM members WHERE members.person_id = presentation_schedule.literature), research = (SELECT name FROM members WHERE members.person_id = presentation_schedule.research); [/code]
Posted
Customer
[quote='srl309' pid='146' dateline=' ***-***-**** '] i dont know why the joins aren't working it looks like they are cross joins and thats why they are returning 3 values you can probably do it like below: [code] select * from presentation_schedule WHERE problem_set IN(select person_id from members) OR literature IN(select person_id from members) OR research IN(select person_id from members); UPDATE presentation_schedule SET problem_set = (SELECT name FROM members WHERE members.person_id = presentation_schedule.problem_set), literature = (SELECT name FROM members WHERE members.person_id = presentation_schedule.literature), research = (SELECT name FROM members WHERE members.person_id = presentation_schedule.research); [/code] [/quote] Thanks for the response srl, I think I misspoke or didn't communicate what I was looking for properly. I'm not looking to update the presentation database with the names of the member database. I can see when I said "replace" that might have been implied. What I am looking for really is a query that I can turn into a VIEW such that the presentation, literature and research columns are replaced by the names in the member table without any post-processing by me. Right now, I have to do two queries, one to pull the members and the other to pull the schedule, then manually loop through the schedule array and replace all instances of the person_id with the name. Right now it is ok, but as the members and schedule length grows this will become increasingly slow So something with the following table output:[code] date problem_set literature research 1/4 4 8 1/8 9 2[/code] Might be replaced by:[code] date problem_set literature research 1/4 person_4 person_8 1/8 person_9 person_2[/code] I do see how the code you provided would allow me to update the presentation_schedule table with the names from members. But I don't think I can translate that to a correct select statement to display. I was trying to think of how I could do an intersection between some various queries to generate the table I needed, and maybe a group_by the date. Going to play around with a few options, but any ideas or help is really appreciated. I took one DB course, and am trying to extend that knowledge to these more complex needs.
Posted
srl309
Programmer
Try something like this: [code]CREATE VIEW v1 AS select p.date, members.name AS problem_set FROM Presentation_Schedule p, members where p.problem_set=members.person_id; CREATE VIEW v2 AS select p.date, members.name AS literature FROM Present ation_Schedule p, members where p.literature=members.person_id; CREATE VIEW v3 AS select p.date, members.name AS research FROM Presentat ion_Schedule p, members where p.research=members.person_id group by p.date;[/code] then select from the views: [code]select v1.date AS date, v1.problem_set AS problem_set, v2.literature AS literature, v3.research AS research from v1 JOIN v2 ON v1.date = v2.date JOIN v3 ON v2.date = v3.date;[/code]
Posted
Customer

Replacing multiple columns with query from another

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More SQLite Questions...

Ask Your SQLite Question & Get An Answer Now!