Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:07 AM
Daniel Cousineau
 
Posts: n/a
Default Joins versus Grouping/Indexing: Normalization Excessive?

So I'm currently designing a database for a web site and intra net for my
campuses student radio. Since I'm not getting paid for this and I'm doing
this in my free time I kinda want to take my time and have the system setup
as "perfectly" as any one college student can.

I'm currently debating on how I want to store all the songs in the system.
Namely I'm not quite sure which way will eek the most performance out of
MySQL.

My plan so far is quite normalized, a songs table with 1:1 relationships
with an Albums, Artists, and Genres table.

The big benefits I see from this is when I'm building the intra net
application I'll want to pull just all of the artists or all of the albums,
etc. However I feel like I'm encountering issues with where to store the
"year" field of an mp3 (do I want it on the album, song, or both) along with
issues like printing everything out at once.

The only other way I can think of thats relatively efficient is to have the
singular songs table and have indexes on albums, artists, and genres.

My question, more out of curiosity than necessity, is which of these would
be more efficient (given that I'll be using the InnoDB storage engine)?

Other relevant facts include it'll be using the latest, stable release of
MySQL 5 and I'll be developing in PHP5 (through CakePHP's database
abstraction layer).

--
Thanks and Gig 'Em!
Daniel Cousineau
http://www.terminalfuture.com/
http://www.linkedin.com/in/dcousineau
dcousineau@gmail.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:07 AM
Micah Stevens
 
Posts: n/a
Default Re: Joins versus Grouping/Indexing: Normalization Excessive?

I think you're approaching this from the wrong angle. You'll want to put
the data at the highest level at which it changes.

i.e. If every song on an album is always the same year, put it at the
album level, however, if it changes from song to song on a particular
album, then you want it at the song level.

Year wouldn't ever apply to artist I don't think, unless they're truly a
one hit wonder.

-Micah

On 04/02/2007 09:14 PM, Daniel Cousineau wrote:
> So I'm currently designing a database for a web site and intra net for my
> campuses student radio. Since I'm not getting paid for this and I'm doing
> this in my free time I kinda want to take my time and have the system
> setup
> as "perfectly" as any one college student can.
>
> I'm currently debating on how I want to store all the songs in the
> system.
> Namely I'm not quite sure which way will eek the most performance out of
> MySQL.
>
> My plan so far is quite normalized, a songs table with 1:1 relationships
> with an Albums, Artists, and Genres table.
>
> The big benefits I see from this is when I'm building the intra net
> application I'll want to pull just all of the artists or all of the
> albums,
> etc. However I feel like I'm encountering issues with where to store the
> "year" field of an mp3 (do I want it on the album, song, or both)
> along with
> issues like printing everything out at once.
>
> The only other way I can think of thats relatively efficient is to
> have the
> singular songs table and have indexes on albums, artists, and genres.
>
> My question, more out of curiosity than necessity, is which of these
> would
> be more efficient (given that I'll be using the InnoDB storage engine)?
>
> Other relevant facts include it'll be using the latest, stable release of
> MySQL 5 and I'll be developing in PHP5 (through CakePHP's database
> abstraction layer).
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:07 AM
Jerry Schwartz
 
Posts: n/a
Default RE: Joins versus Grouping/Indexing: Normalization Excessive?

Do you really mean 1:1 relationships? A song might have more than one
artist, album, or genre. Could a song have no album at all, such as
something that was released in MP3 format? Also, you might have more than
one version of a song. You might need a separate table for recordings, with
each song having one or more recordings. That would be a good place to keep
the release information, rather than storing it with the song.

The biggest problem would be to figure out how to index the songs,
themselves. I don't have a good suggestion for that off the top of my head.

That all being said, there's no reason I can think of not to normalize the
data.

Regards,

Jerry Schwartz
Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341


> -----Original Message-----
> From: Daniel Cousineau [mailto:dcousineau@gmail.com]
> Sent: Tuesday, April 03, 2007 12:15 AM
> To: mysql@lists.mysql.com
> Subject: Joins versus Grouping/Indexing: Normalization Excessive?
>
> So I'm currently designing a database for a web site and
> intra net for my
> campuses student radio. Since I'm not getting paid for this
> and I'm doing
> this in my free time I kinda want to take my time and have
> the system setup
> as "perfectly" as any one college student can.
>
> I'm currently debating on how I want to store all the songs
> in the system.
> Namely I'm not quite sure which way will eek the most
> performance out of
> MySQL.
>
> My plan so far is quite normalized, a songs table with 1:1
> relationships
> with an Albums, Artists, and Genres table.
>
> The big benefits I see from this is when I'm building the intra net
> application I'll want to pull just all of the artists or all
> of the albums,
> etc. However I feel like I'm encountering issues with where
> to store the
> "year" field of an mp3 (do I want it on the album, song, or
> both) along with
> issues like printing everything out at once.
>
> The only other way I can think of thats relatively efficient
> is to have the
> singular songs table and have indexes on albums, artists, and genres.
>
> My question, more out of curiosity than necessity, is which
> of these would
> be more efficient (given that I'll be using the InnoDB
> storage engine)?
>
> Other relevant facts include it'll be using the latest,
> stable release of
> MySQL 5 and I'll be developing in PHP5 (through CakePHP's database
> abstraction layer).
>
> --
> Thanks and Gig 'Em!
> Daniel Cousineau
> http://www.terminalfuture.com/
> http://www.linkedin.com/in/dcousineau
> dcousineau@gmail.com
>




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 06:07 AM
murthy gandikota
 
Posts: n/a
Default LEFT/RIGHT Joins not working

I tried the following 2 SQL's and the results are less than satisfactory. The RIGHT join does not show where disposition is NULL. The LEFT join shows dispositions as NULL where they shouldn't be. Also the LEFT join generates more dupes. Any way to fix this?

select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS, cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as SSN, disposition.disposition as DISPOSITION, leadSource.source as SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust RIGHT JOIN disposition on (cust.disposition=disposition.id) RIGHT JOIN leadSource on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and cust.disposition > 0 order by SOURCE, DISPOSITION

select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS, cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as SSN, disposition.disposition as DISPOSITION, leadSource.source as SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust LEFT JOIN disposition on (cust.disposition=disposition.id) LEFT JOIN leadSource on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and cust.disposition > 0 order by SOURCE, DISPOSITION

The MYSQL has the following version

mysql Ver 14.7 Distrib 5.0.2-alpha, for pc-linux (i686)

Thanks for your help
Murthy


---------------------------------
Don't get soaked. Take a quick peek at the forecast
with theYahoo! Search weather shortcut.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 06:07 AM
Michael Dykman
 
Posts: n/a
Default Re: LEFT/RIGHT Joins not working

a left join and a right join are 2 very distinct things... It is not
clear from your text what it is you exactly are going for here but I
doubt that applying either LEFT or RIGHT to ALL of your (many) joins
is going to give it to you. You need to stop and examine the
relationships between the tables in this query and determine which
class of JOIN you will need (and there are more than just these 2).

The description you gave of your results using RIGHT and LEFT
universally are consistent with what I would expect from those types
of joins. I suggest that you read this page very carefully before you
continue:

http://dev.mysql.com/doc/refman/5.1/en/join.html

- michael

On 4/3/07, murthy gandikota <murthy_gandikota@yahoo.com> wrote:
> I tried the following 2 SQL's and the results are less than satisfactory. The RIGHT join does not show where disposition is NULL. The LEFT join shows dispositions as NULL where they shouldn't be. Also the LEFT join generates more dupes. Any way to fix this?
>
> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS, cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as SSN, disposition.disposition as DISPOSITION, leadSource.source as SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust RIGHT JOIN disposition on (cust.disposition=disposition.id) RIGHT JOIN leadSource on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and cust.disposition > 0 order by SOURCE, DISPOSITION
>
> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS, cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as SSN, disposition.disposition as DISPOSITION, leadSource.source as SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust LEFT JOIN disposition on (cust.disposition=disposition.id) LEFT JOIN leadSource on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and cust.disposition > 0 order by SOURCE, DISPOSITION
>
> The MYSQL has the following version
>
> mysql Ver 14.7 Distrib 5.0.2-alpha, for pc-linux (i686)
>
> Thanks for your help
> Murthy
>
>
> ---------------------------------
> Don't get soaked. Take a quick peek at the forecast
> with theYahoo! Search weather shortcut.



--
- michael dykman
- mdykman@gmail.com

- All models are wrong. Some models are useful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 06:08 AM
murthy gandikota
 
Posts: n/a
Default Re: LEFT/RIGHT Joins not working

Hi Mike
Thanks for your input. I read the page before and it caused more confusion.
May be an example would clarify this:

create table `cust` (`ssn` varchar(10), `source` int(3) , `disposition` int(3));
insert into cust (ssn, source, disposition) values ('123456789', 1, 2);
insert into cust (ssn, source, disposition) values ('123456780', 2, 1);
insert into cust (ssn, source, disposition) values ('123456781', NULL, NULL);

create table `source` (`id` int(3), `source` varchar(10));
insert into source(id, source) values (1, 'source1');
insert into source(id,source) values (2, 'source2');

create table `disposition` (`id` int(3), `disposition` varchar(10));
insert into disposition (id, disposition) values (1, 'dispo1');
insert into disposition(id,disposition) values (2, 'dispo2');

Now I run the sql:
select cust.ssn, disposition.disposition, source.source from cust LEFT JOIN source ON (cust.source=source.id) LEFT JOIN disposition ON (cust.disposition=disposition.id)

+-----------+-------------+---------+
| ssn | disposition | source |
+-----------+-------------+---------+
| 123456789 | dispo2 | source1 |
| 123456789 | dispo2 | source1 |
| 123456780 | dispo1 | source2 |
| 123456780 | dispo1 | source2 |
| 123456781 | NULL | NULL |
+-----------+-------------+---------+

I don't want this cos the ssn 123456780 is shown twice

select cust.ssn, disposition.disposition, source.source from cust RIGHT JOIN source ON (cust.source=source.id) RIGHT JOIN disposition ON (cust.disposition=disposition.id)

+-----------+-------------+---------+
| ssn | disposition | source |
+-----------+-------------+---------+
| 123456789 | dispo2 | source1 |
| 123456789 | dispo2 | source1 |
| 123456780 | dispo1 | source2 |
| 123456780 | dispo1 | source2 |
+-----------+-------------+---------+

This has the same problem.

All I want is

+-----------+-------------+---------+
| ssn | disposition | source |
+-----------+-------------+---------+
| 123456789 | dispo2 | source1 |
| 123456780 | dispo1 | source2 |
| 123456781 | NULL | NULL |
+-----------+-------------+---------+

I'd appreciate your help.
Thanks
Murthy
Michael Dykman <mdykman@gmail.com> wrote:
a left join and a right join are 2 very distinct things... It is not
clear from your text what it is you exactly are going for here but I
doubt that applying either LEFT or RIGHT to ALL of your (many) joins
is going to give it to you. You need to stop and examine the
relationships between the tables in this query and determine which
class of JOIN you will need (and there are more than just these 2).

The description you gave of your results using RIGHT and LEFT
universally are consistent with what I would expect from those types
of joins. I suggest that you read this page very carefully before you
continue:

http://dev.mysql.com/doc/refman/5.1/en/join.html

- michael

On 4/3/07, murthy gandikota wrote:
> I tried the following 2 SQL's and the results are less than satisfactory. The RIGHT join does not show where disposition is NULL. The LEFT join shows dispositions as NULL where they shouldn't be. Also the LEFT join generates more dupes. Any way to fix this?
>
> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS, cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as SSN, disposition.disposition as DISPOSITION, leadSource.source as SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust RIGHT JOIN disposition on (cust.disposition=disposition.id) RIGHT JOIN leadSource on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and cust.disposition > 0 order by SOURCE, DISPOSITION
>
> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS, cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as SSN, disposition.disposition as DISPOSITION, leadSource.source as SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust LEFT JOIN disposition on (cust.disposition=disposition.id) LEFT JOIN leadSource on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and cust.disposition > 0 order by SOURCE, DISPOSITION
>
> The MYSQL has the following version
>
> mysql Ver 14.7 Distrib 5.0.2-alpha, for pc-linux (i686)
>
> Thanks for your help
> Murthy
>
>
> ---------------------------------
> Don't get soaked. Take a quick peek at the forecast
> with theYahoo! Search weather shortcut.



--
- michael dykman
- mdykman@gmail.com

- All models are wrong. Some models are useful.



---------------------------------
8:00? 8:25? 8:40? Find a flick in no time
with theYahoo! Search movie showtime shortcut.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 06:08 AM
Mogens Melander
 
Posts: n/a
Default Re: LEFT/RIGHT Joins not working

Well, trying your example gives me the expected result.

select cust.ssn, disposition.disposition, source.source
from cust LEFT JOIN source ON (cust.source=source.id)
LEFT JOIN disposition ON (cust.disposition=disposition.id);

'123456789', 'dispo2', 'source1'
'123456780', 'dispo1', 'source2'
'123456781', null, null

On Wed, April 4, 2007 00:03, murthy gandikota wrote:
> Hi Mike
> Thanks for your input. I read the page before and it caused more
> confusion.
> May be an example would clarify this:
>
> create table `cust` (`ssn` varchar(10), `source` int(3) , `disposition`
> int(3));
> insert into cust (ssn, source, disposition) values ('123456789', 1, 2);
> insert into cust (ssn, source, disposition) values ('123456780', 2, 1);
> insert into cust (ssn, source, disposition) values ('123456781', NULL,
> NULL);
>
> create table `source` (`id` int(3), `source` varchar(10));
> insert into source(id, source) values (1, 'source1');
> insert into source(id,source) values (2, 'source2');
>
> create table `disposition` (`id` int(3), `disposition` varchar(10));
> insert into disposition (id, disposition) values (1, 'dispo1');
> insert into disposition(id,disposition) values (2, 'dispo2');
>
> Now I run the sql:
> select cust.ssn, disposition.disposition, source.source from cust LEFT
> JOIN source ON (cust.source=source.id) LEFT JOIN disposition ON
> (cust.disposition=disposition.id)
>
> +-----------+-------------+---------+
> | ssn | disposition | source |
> +-----------+-------------+---------+
> | 123456789 | dispo2 | source1 |
> | 123456789 | dispo2 | source1 |
> | 123456780 | dispo1 | source2 |
> | 123456780 | dispo1 | source2 |
> | 123456781 | NULL | NULL |
> +-----------+-------------+---------+
>
> I don't want this cos the ssn 123456780 is shown twice
>
> select cust.ssn, disposition.disposition, source.source from cust RIGHT
> JOIN source ON (cust.source=source.id) RIGHT JOIN disposition ON
> (cust.disposition=disposition.id)
>
> +-----------+-------------+---------+
> | ssn | disposition | source |
> +-----------+-------------+---------+
> | 123456789 | dispo2 | source1 |
> | 123456789 | dispo2 | source1 |
> | 123456780 | dispo1 | source2 |
> | 123456780 | dispo1 | source2 |
> +-----------+-------------+---------+
>
> This has the same problem.
>
> All I want is
>
> +-----------+-------------+---------+
> | ssn | disposition | source |
> +-----------+-------------+---------+
> | 123456789 | dispo2 | source1 |
> | 123456780 | dispo1 | source2 |
> | 123456781 | NULL | NULL |
> +-----------+-------------+---------+
>
> I'd appreciate your help.
> Thanks
> Murthy
> Michael Dykman <mdykman@gmail.com> wrote:
> a left join and a right join are 2 very distinct things... It is not
> clear from your text what it is you exactly are going for here but I
> doubt that applying either LEFT or RIGHT to ALL of your (many) joins
> is going to give it to you. You need to stop and examine the
> relationships between the tables in this query and determine which
> class of JOIN you will need (and there are more than just these 2).
>
> The description you gave of your results using RIGHT and LEFT
> universally are consistent with what I would expect from those types
> of joins. I suggest that you read this page very carefully before you
> continue:
>
> http://dev.mysql.com/doc/refman/5.1/en/join.html
>
> - michael
>
> On 4/3/07, murthy gandikota wrote:
>> I tried the following 2 SQL's and the results are less than
>> satisfactory. The RIGHT join does not show where disposition is NULL.
>> The LEFT join shows dispositions as NULL where they shouldn't be. Also
>> the LEFT join generates more dupes. Any way to fix this?
>>
>> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS,
>> cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as
>> SSN, disposition.disposition as DISPOSITION, leadSource.source as
>> SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as
>> CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust RIGHT JOIN
>> disposition on (cust.disposition=disposition.id) RIGHT JOIN leadSource
>> on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and
>> cust.disposition > 0 order by SOURCE, DISPOSITION
>>
>> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS,
>> cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as
>> SSN, disposition.disposition as DISPOSITION, leadSource.source as
>> SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as
>> CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust LEFT JOIN
>> disposition on (cust.disposition=disposition.id) LEFT JOIN leadSource on
>> (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and
>> cust.disposition > 0 order by SOURCE, DISPOSITION
>>
>> The MYSQL has the following version
>>
>> mysql Ver 14.7 Distrib 5.0.2-alpha, for pc-linux (i686)
>>
>> Thanks for your help
>> Murthy
>>
>>
>> ---------------------------------
>> Don't get soaked. Take a quick peek at the forecast
>> with theYahoo! Search weather shortcut.

>
>
> --
> - michael dykman
> - mdykman@gmail.com
>
> - All models are wrong. Some models are useful.
>
>
>
> ---------------------------------
> 8:00? 8:25? 8:40? Find a flick in no time
> with theYahoo! Search movie showtime shortcut.
> --
> This message has been scanned for viruses and
> dangerous content by OpenProtect(http://www.openprotect.com), and is
> believed to be clean.
>
>



--
Later

Mogens Melander
+45 40 85 71 38
+66 870 133 224



--
This message has been scanned for viruses and
dangerous content by OpenProtect(http://www.openprotect.com), and is
believed to be clean.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 06:08 AM
murthy gandikota
 
Posts: n/a
Default Re: LEFT/RIGHT Joins not working

Many thanks for your input. Looks like the older version of mysql, preceding 5.0 has some problems. I've to upgrade mysql now. :-(

Thanks again.

Mogens Melander <mogens@fumlersoft.dk> wrote:
Well, trying your example gives me the expected result.

select cust.ssn, disposition.disposition, source.source
from cust LEFT JOIN source ON (cust.source=source.id)
LEFT JOIN disposition ON (cust.disposition=disposition.id);

'123456789', 'dispo2', 'source1'
'123456780', 'dispo1', 'source2'
'123456781', null, null

On Wed, April 4, 2007 00:03, murthy gandikota wrote:
> Hi Mike
> Thanks for your input. I read the page before and it caused more
> confusion.
> May be an example would clarify this:
>
> create table `cust` (`ssn` varchar(10), `source` int(3) , `disposition`
> int(3));
> insert into cust (ssn, source, disposition) values ('123456789', 1, 2);
> insert into cust (ssn, source, disposition) values ('123456780', 2, 1);
> insert into cust (ssn, source, disposition) values ('123456781', NULL,
> NULL);
>
> create table `source` (`id` int(3), `source` varchar(10));
> insert into source(id, source) values (1, 'source1');
> insert into source(id,source) values (2, 'source2');
>
> create table `disposition` (`id` int(3), `disposition` varchar(10));
> insert into disposition (id, disposition) values (1, 'dispo1');
> insert into disposition(id,disposition) values (2, 'dispo2');
>
> Now I run the sql:
> select cust.ssn, disposition.disposition, source.source from cust LEFT
> JOIN source ON (cust.source=source.id) LEFT JOIN disposition ON
> (cust.disposition=disposition.id)
>
> +-----------+-------------+---------+
> | ssn | disposition | source |
> +-----------+-------------+---------+
> | 123456789 | dispo2 | source1 |
> | 123456789 | dispo2 | source1 |
> | 123456780 | dispo1 | source2 |
> | 123456780 | dispo1 | source2 |
> | 123456781 | NULL | NULL |
> +-----------+-------------+---------+
>
> I don't want this cos the ssn 123456780 is shown twice
>
> select cust.ssn, disposition.disposition, source.source from cust RIGHT
> JOIN source ON (cust.source=source.id) RIGHT JOIN disposition ON
> (cust.disposition=disposition.id)
>
> +-----------+-------------+---------+
> | ssn | disposition | source |
> +-----------+-------------+---------+
> | 123456789 | dispo2 | source1 |
> | 123456789 | dispo2 | source1 |
> | 123456780 | dispo1 | source2 |
> | 123456780 | dispo1 | source2 |
> +-----------+-------------+---------+
>
> This has the same problem.
>
> All I want is
>
> +-----------+-------------+---------+
> | ssn | disposition | source |
> +-----------+-------------+---------+
> | 123456789 | dispo2 | source1 |
> | 123456780 | dispo1 | source2 |
> | 123456781 | NULL | NULL |
> +-----------+-------------+---------+
>
> I'd appreciate your help.
> Thanks
> Murthy
> Michael Dykman wrote:
> a left join and a right join are 2 very distinct things... It is not
> clear from your text what it is you exactly are going for here but I
> doubt that applying either LEFT or RIGHT to ALL of your (many) joins
> is going to give it to you. You need to stop and examine the
> relationships between the tables in this query and determine which
> class of JOIN you will need (and there are more than just these 2).
>
> The description you gave of your results using RIGHT and LEFT
> universally are consistent with what I would expect from those types
> of joins. I suggest that you read this page very carefully before you
> continue:
>
> http://dev.mysql.com/doc/refman/5.1/en/join.html
>
> - michael
>
> On 4/3/07, murthy gandikota wrote:
>> I tried the following 2 SQL's and the results are less than
>> satisfactory. The RIGHT join does not show where disposition is NULL.
>> The LEFT join shows dispositions as NULL where they shouldn't be. Also
>> the LEFT join generates more dupes. Any way to fix this?
>>
>> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS,
>> cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as
>> SSN, disposition.disposition as DISPOSITION, leadSource.source as
>> SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as
>> CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust RIGHT JOIN
>> disposition on (cust.disposition=disposition.id) RIGHT JOIN leadSource
>> on (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and
>> cust.disposition > 0 order by SOURCE, DISPOSITION
>>
>> select cust.first as FIRST, cust.last as LAST, cust.address AS ADDRESS,
>> cust.city as CITY, cust.state as STATE, cust.zip as ZIP, cust.ssn as
>> SSN, disposition.disposition as DISPOSITION, leadSource.source as
>> SOURCE, cust.loanBalance AS LOANBALANCE, cust.currentPayment as
>> CURRENTPAYMENT, cust.newPayment as NEWPAYMENT from cust LEFT JOIN
>> disposition on (cust.disposition=disposition.id) LEFT JOIN leadSource on
>> (cust.source=leadSource.id) where agentCode=11 and newPayment > 0 and
>> cust.disposition > 0 order by SOURCE, DISPOSITION
>>
>> The MYSQL has the following version
>>
>> mysql Ver 14.7 Distrib 5.0.2-alpha, for pc-linux (i686)
>>
>> Thanks for your help
>> Murthy
>>
>>
>> ---------------------------------
>> Don't get soaked. Take a quick peek at the forecast
>> with theYahoo! Search weather shortcut.

>
>
> --
> - michael dykman
> - mdykman@gmail.com
>
> - All models are wrong. Some models are useful.
>
>
>
> ---------------------------------
> 8:00? 8:25? 8:40? Find a flick in no time
> with theYahoo! Search movie showtime shortcut.
> --
> This message has been scanned for viruses and
> dangerous content by OpenProtect(http://www.openprotect.com), and is
> believed to be clean.
>
>



--
Later

Mogens Melander
+45 40 85 71 38
+66 870 133 224



--
This message has been scanned for viruses and
dangerous content by OpenProtect(http://www.openprotect.com), and is
believed to be clean.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=p...software.co.uk


--- Scanned by M+ Guardian Extreme Messaging Firewall by Messaging Architects ---




---------------------------------
Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:23 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409