Ask a Question related to MySQL, Design and Development.
-
Bosconian #1
INNER JOIN query question
I have 2 tables with the following columns (other data fields omitted for
brevity):
cases.caseid
cases.uid
profiles.uid
profiles.locationid
I need to return a list of caseid's based on a uid's locationid.
Before executing the query, I only know the uid. I could retrieve the uid's
locationid with a separate query, which would then make getting a list of
caseid's easy.
Example:
SELECT p.locationid
FROM profile p
WHERE p.uid = 1
SELECT c.caseid
FROM cases c
INNER JOIN profile p ON p.uid = c.uid
WHERE p.locationid = 1
However, for learning and efficiency purposes is there a way to do this with
one query?
Thanks.
Bosconian Guest
-
sql join query
Hi, I have a little problem that's driving me nuts, I'm sure there's a simple solution that I'm overlooking. The problem is this (I'm giving... -
Add another join to a query
I need to add to the SELECT item "C.CATEGORY_ID" to the following query (another join?): Category_id is a column of table "blog_categories" which... -
question about SQL query and cfoutput with INNER JOIN
I have a query that pulls data from two related tables (an Article Table and a Photo table, linked by ArticleID) Lets say i have 3 photos that are... -
Query, view join question.
Hi Tom, I could give you access to the database itself if needed. But these are the actual tables and view. I hope I will never make any tpo's... -
Query, view join question.
Hi all, I have 2 tables: table1 with the columns objectid, refobjectid, commonvaluecol and value1. table2 with the columns objectid,... -
Nicholas Sherlock #2
Re: INNER JOIN query question
Bosconian wrote:
Do you mean this?> SELECT p.locationid
> FROM profile p
> WHERE p.uid = 1
>
> SELECT c.caseid
> FROM cases c
> INNER JOIN profile p ON p.uid = c.uid
> WHERE p.locationid = 1
>
> However, for learning and efficiency purposes is there a way to do this with
> one query?
SELECT p.locationid, c.caseid
FROM profile p
INNER JOIN cases c ON p.uid=c.uid
WHERE p.uid = 1
Cheers,
Nicholas Sherlock
Nicholas Sherlock Guest
-
Bosconian #3
Re: INNER JOIN query question
"Nicholas Sherlock" <N.sherlock@gmail.com> wrote in message
news:dsn1a4$si9$3@lust.ihug.co.nz...with> Bosconian wrote:> > SELECT p.locationid
> > FROM profile p
> > WHERE p.uid = 1
> >
> > SELECT c.caseid
> > FROM cases c
> > INNER JOIN profile p ON p.uid = c.uid
> > WHERE p.locationid = 1
> >
> > However, for learning and efficiency purposes is there a way to do thisUnfortunately, no.>> > one query?
> Do you mean this?
>
> SELECT p.locationid, c.caseid
> FROM profile p
> INNER JOIN cases c ON p.uid=c.uid
> WHERE p.uid = 1
>
> Cheers,
> Nicholas Sherlock
Allow me to rephrase the question.
I need a list of caseid's for those uid's which match the current uid's
locationid.
So for example let's say the tables contain the following data:
case.caseid, case.uid
3, 1
5, 2
7, 3
profile.uid, profile.locationid
1 1
2 2
3 2
Assuming the current uid equals '2', the results would return caseid's 5 &
7. Make sense?
Bosconian Guest
-
Vincent Lascaux #4
Re: INNER JOIN query question
> So for example let's say the tables contain the following data:
SELECT case.caseid FROM Case>
> case.caseid, case.uid
> 3, 1
> 5, 2
> 7, 3
>
> profile.uid, profile.locationid
> 1 1
> 2 2
> 3 2
>
> Assuming the current uid equals '2', the results would return caseid's 5 &
> 7. Make sense?
INNER JOIN Profile ON case.uid = profile.uid
WHERE profile.locationid = 2
Should do it I think
--
Vincent
Vincent Lascaux Guest
-
Bosconian #5
Re: INNER JOIN query question
"Vincent Lascaux" <nospam@nospam.org> wrote in message
news:43ef83a2$0$311$626a14ce@news.free.fr...&> > So for example let's say the tables contain the following data:
> >
> > case.caseid, case.uid
> > 3, 1
> > 5, 2
> > 7, 3
> >
> > profile.uid, profile.locationid
> > 1 1
> > 2 2
> > 3 2
> >
> > Assuming the current uid equals '2', the results would return caseid's 5You're right, except I don't know the current uid's locationid beforehand>> > 7. Make sense?
> SELECT case.caseid FROM Case
> INNER JOIN Profile ON case.uid = profile.uid
> WHERE profile.locationid = 2
>
> Should do it I think
>
> --
> Vincent
>
>
(unless its retreived in a separate query, which currently seems to be the
easy way to go about this.)
Bosconian Guest
-
Vincent Lascaux #6
Re: INNER JOIN query question
>> > case.caseid, case.uid
I don't get it... What is the '2' in your example. If you don't know the> &>> > 3, 1
>> > 5, 2
>> > 7, 3
>> >
>> > profile.uid, profile.locationid
>> > 1 1
>> > 2 2
>> > 3 2
>> >
>> > Assuming the current uid equals '2', the results would return caseid's
>> > 5>>> > 7. Make sense?
> You're right, except I don't know the current uid's locationid beforehand
> (unless its retreived in a separate query, which currently seems to be the
> easy way to go about this.)
uid, how can you select the row that match that uid?
--
Vincent
Vincent Lascaux Guest
-
Bosconian #7
Re: INNER JOIN query question
"Vincent Lascaux" <nospam@nospam.org> wrote in message
news:43ef9007$0$304$626a14ce@news.free.fr...caseid's> >> > case.caseid, case.uid
> >> > 3, 1
> >> > 5, 2
> >> > 7, 3
> >> >
> >> > profile.uid, profile.locationid
> >> > 1 1
> >> > 2 2
> >> > 3 2
> >> >
> >> > Assuming the current uid equals '2', the results would returnbeforehand> > &> >> > 5> >> >> > 7. Make sense?
> > You're right, except I don't know the current uid's locationidthe> > (unless its retreived in a separate query, which currently seems to beThe data shown was for demonstration purposes only.>> > easy way to go about this.)
> I don't get it... What is the '2' in your example. If you don't know the
> uid, how can you select the row that match that uid?
>
> --
> Vincent
>
>
In any event I opted to retrieve the locationid before, which makes my life
MUCH easier.
Bosconian Guest



Reply With Quote

