473,799 Members | 3,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Join

Hello,

I have set up a database for movies. In one table (Movies) I have
movie names, and production years, and also genres. In another table
(Directors), I keep the directors and the movies they directed.
Another table (People) keeps the names of the people. Everybody will
have a unique ID. I have created a query like below to show the name
and production year of the movie, the director name and the genre of
the movie. Genres are also defined in a tabled called Genres.

SELECT Movies.Name, Movies.Year, People.Name AS Director, Genres.Genre
FROM Movies INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN Genres ON Movies.Genre = Genres.ID INNER JOIN People ON
Directors.ID = People.ID WHERE (Movies.ID = @MoviesID)
The problem is that it does not return any result. What might be the
problem?
Thanks in advance...

Mar 12 '07 #1
5 2741

Where you are joining on Directors that 1st Join There
looks like directors should be the people table...
Dave P
"Dot Net Daddy" <ca********@gma il.comwrote in message
news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
Hello,

I have set up a database for movies. In one table (Movies) I have
movie names, and production years, and also genres. In another table
(Directors), I keep the directors and the movies they directed.
Another table (People) keeps the names of the people. Everybody will
have a unique ID. I have created a query like below to show the name
and production year of the movie, the director name and the genre of
the movie. Genres are also defined in a tabled called Genres.

SELECT Movies.Name, Movies.Year, People.Name AS Director, Genres.Genre
FROM Movies INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN Genres ON Movies.Genre = Genres.ID INNER JOIN People ON
Directors.ID = People.ID WHERE (Movies.ID = @MoviesID)
The problem is that it does not return any result. What might be the
problem?
Thanks in advance...

Mar 12 '07 #2
it looks like you have many different types of peopls in ur peoples table
directors and
select * from Movies M (nolock)
join peoples d (nolock) d.directorsGrou p=m.DirectorsGr oup
join peoples. a (nolock) a.ActorsGroup=m .ActorsGroup
join GenRes G (nolock) g.Genres=m.Genr es
above is a sample join of somthing of what your data may look like
h
"Dave P" <an*******@yaho o.comwrote in message
news:5k******** *********@newss vr21.news.prodi gy.net...
>
Where you are joining on Directors that 1st Join There
looks like directors should be the people table...
Dave P
"Dot Net Daddy" <ca********@gma il.comwrote in message
news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
>Hello,

I have set up a database for movies. In one table (Movies) I have
movie names, and production years, and also genres. In another table
(Directors), I keep the directors and the movies they directed.
Another table (People) keeps the names of the people. Everybody will
have a unique ID. I have created a query like below to show the name
and production year of the movie, the director name and the genre of
the movie. Genres are also defined in a tabled called Genres.

SELECT Movies.Name, Movies.Year, People.Name AS Director, Genres.Genre
FROM Movies INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN Genres ON Movies.Genre = Genres.ID INNER JOIN People ON
Directors.ID = People.ID WHERE (Movies.ID = @MoviesID)
The problem is that it does not return any result. What might be the
problem?
Thanks in advance...


Mar 12 '07 #3
Dot Net Daddy wrote:
I have set up a database for movies. In one table (Movies) I have
movie names, and production years, and also genres. In another table
(Directors), I keep the directors and the movies they directed.
Based on your query, I assume that you are /not/ making the classic
violation of 1NF, which would look like:

ID | ListOfMovieIDs
---+---------------
1 | 1,2
2 | 3
3 | 3

but rather you have done it correctly:

ID | MovieID
---+--------
1 | 1
1 | 2
2 | 3
3 | 3

Personally, I would rename the ID column to DirectorID. In particular,
some tools (e.g. the Smart Linking option in Crystal Reports) will give
more useful results if you do this. Similarly for the ID columns in
the other tables.
Another table (People) keeps the names of the people. Everybody will
have a unique ID. I have created a query like below to show the name
and production year of the movie, the director name and the genre of
the movie. Genres are also defined in a tabled called Genres.

SELECT Movies.Name, Movies.Year, People.Name AS Director, Genres.Genre
FROM Movies INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN Genres ON Movies.Genre = Genres.ID INNER JOIN People ON
Directors.ID = People.ID WHERE (Movies.ID = @MoviesID)
The problem is that it does not return any result. What might be the
problem?
Build up the query one level at a time:

SELECT Movies.Name, Movies.Year
FROM Movies
WHERE Movies.ID = @MoviesID

If this returns zero rows, then @MoviesID is not in the Movies table.

SELECT Movies.Name, Movies.Year, Director.ID as DirectorID
FROM Movies
INNER JOIN Directors ON Movies.ID = Directors.Movie ID
WHERE Movies.ID = @MoviesID

If this returns zero rows, then Movies.ID is not in the Directors
table.

SELECT Movies.Name, Movies.Year, People.Name as Director
FROM Movies
INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN People ON Directors.ID = People.ID
WHERE Movies.ID = @MoviesID

If this returns zero rows, then Directors.ID is not in the People
table. Fix all such cases, then add a foreign-key constraint to
prevent it from happening again.

SELECT Movies.Name, Movies.Year, People.Name as Director, Genres.Genre
FROM Movies
INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN People ON Directors.ID = People.ID
INNER JOIN Genres ON Movies.Genre = Genres.ID
WHERE Movies.ID = @MoviesID

If this returns zero rows, then Movies.Genre is not in the Genres
table. Fix and add constraint.

Alternatively, you can replace any/all of the INNER JOINs with
LEFT OUTER JOINs. You will then get NULLs from that branch of
the join tree, e.g. if Movies.ID is not in the Directors table
then anything you attempt to get from Directors *or* People will
be NULL. COALESCE(SomeFi eld,'DefaultVal ue') may be of interest.
Mar 12 '07 #4
Im Confused about ur tables
movies MovieId(identit y), other columns, DirectorId (from Directors),
genresId (from Genres)
if your table is not designd somewhat like the above, gonna be hard to link
the child tables(ref tables, directors, genres)
movie
movieid (identy)
title
genres (id from genres) could be identy in genres or another unique id
director (id from Director) could be identy in genres or another unique id
yearmade
Studio
etc

hope the above helps
DaveP
"Ed Murphy" <em*******@soca l.rr.comwrote in message
news:45******** *************** @roadrunner.com ...
Dot Net Daddy wrote:
>I have set up a database for movies. In one table (Movies) I have
movie names, and production years, and also genres. In another table
(Directors), I keep the directors and the movies they directed.

Based on your query, I assume that you are /not/ making the classic
violation of 1NF, which would look like:

ID | ListOfMovieIDs
---+---------------
1 | 1,2
2 | 3
3 | 3

but rather you have done it correctly:

ID | MovieID
---+--------
1 | 1
1 | 2
2 | 3
3 | 3

Personally, I would rename the ID column to DirectorID. In particular,
some tools (e.g. the Smart Linking option in Crystal Reports) will give
more useful results if you do this. Similarly for the ID columns in
the other tables.
>Another table (People) keeps the names of the people. Everybody will
have a unique ID. I have created a query like below to show the name
and production year of the movie, the director name and the genre of
the movie. Genres are also defined in a tabled called Genres.

SELECT Movies.Name, Movies.Year, People.Name AS Director, Genres.Genre
FROM Movies INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN Genres ON Movies.Genre = Genres.ID INNER JOIN People ON
Directors.ID = People.ID WHERE (Movies.ID = @MoviesID)
The problem is that it does not return any result. What might be the
problem?

Build up the query one level at a time:

SELECT Movies.Name, Movies.Year
FROM Movies
WHERE Movies.ID = @MoviesID

If this returns zero rows, then @MoviesID is not in the Movies table.

SELECT Movies.Name, Movies.Year, Director.ID as DirectorID
FROM Movies
INNER JOIN Directors ON Movies.ID = Directors.Movie ID
WHERE Movies.ID = @MoviesID

If this returns zero rows, then Movies.ID is not in the Directors
table.

SELECT Movies.Name, Movies.Year, People.Name as Director
FROM Movies
INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN People ON Directors.ID = People.ID
WHERE Movies.ID = @MoviesID

If this returns zero rows, then Directors.ID is not in the People
table. Fix all such cases, then add a foreign-key constraint to
prevent it from happening again.

SELECT Movies.Name, Movies.Year, People.Name as Director, Genres.Genre
FROM Movies
INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN People ON Directors.ID = People.ID
INNER JOIN Genres ON Movies.Genre = Genres.ID
WHERE Movies.ID = @MoviesID

If this returns zero rows, then Movies.Genre is not in the Genres
table. Fix and add constraint.

Alternatively, you can replace any/all of the INNER JOINs with
LEFT OUTER JOINs. You will then get NULLs from that branch of
the join tree, e.g. if Movies.ID is not in the Directors table
then anything you attempt to get from Directors *or* People will
be NULL. COALESCE(SomeFi eld,'DefaultVal ue') may be of interest.

Mar 14 '07 #5
>I have set up a database for movies. <<

Actually, you don't; such things already exist and you can download
them.
>In one table (Movies) I have movie names, and production years, and also genres. In another table (Directors), I keep the directors and the movies they directed. <<
If a movie can have more than one director, then where is the
relationship table?
>Another table (People) keeps the names of the people. Everybody will have a unique ID. <<
It is nice to know you do not consider Directors to be people and put
them ina separate table :)

Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
>I have created a query like below to show the name and production year of the movie, the director name and the genre of the movie. <<
What you posted is completely wrong. The data element names are too
vague to be useful and involve reserved words. You are so far off
base, you even have the magical, universal id column which changes
meaning from table to table! Tell me that you did not use an IDENTITY
in all your tables for this.

CREATE TABLE Movies
(<<industry standard if>>,
release_year INTEGER NOT NULL,
genre_code CHAR(10) NOT NULL,
etc.);

CREATE TABLE Personnel (..) -- SAG number as id?

CREATE TABLE Crew (..) -- includes role played by personnel on a movie

Start over with a relational design or your teacher will give you a
really bad grade.
>
SELECT Movies.Name, Movies.Year, People.Name AS Director, Genres.Genre
FROM Movies INNER JOIN Directors ON Movies.ID = Directors.Movie ID
INNER JOIN Genres ON Movies.Genre = Genres.ID INNER JOIN People ON
Directors.ID = People.ID WHERE (Movies.ID = @MoviesID)

The problem is that it does not return any result. What might be the
problem?

Thanks in advance...

Mar 16 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3075
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me solve my problem. I'll turn to MySQL doc after getting through this pressing project. Thanks a lot Roger! Babale -----Urspr=FCngliche Nachricht-----
2
1953
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1 that needs to "left" join to table1A, table1B, and table1C which is corrently done with the following: select table1.x, table1a.y, table1b.z, table1c.q from table1 left join table1a on table1.ID = table1a.ID left join table1b on table1.ID =...
3
3360
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four inner joins, as follows : SELECT DISTINCT upcards.id,statuskey.status,upcards.firstname,upcards.lastname,originkey.ori gin,associatekey.username,associatekey2.username,upcards.deleted FROM upcards,status,origins,associates INNER JOIN status...
1
2270
by: Beachvolleyballer | last post by:
hi there anyone had an idea to join following 2 queries to 1???? ----- QUERY 1 --------------------------------------------- SELECT TMS_CaseF_2.Name AS TCDomain_0, TMS_CaseF_3.Name AS TCDomain_1, TMS.CaseF.Name AS TCFolder_2, TMS_CaseF_1.Name AS TCFolder_3,
8
4975
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and also display their corresponding entries in arb, but if there is NO entry in arb I still want it to show up as NULL or something, so that I can get the attention that there IS no language associated with that article.
7
1686
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem that we fixed, but I'd like to understand 'why' it was happening and just don't get it yet. Here's the starting query (reduced to simple prefixes): ----INITIAL-----
3
23101
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but he doesn't know how to do that, or even if he can, and i don't have to time to learn DB2 from scratch right now. The following SQL Query is a trimmed sample of the full View (i.e. Logical) definition - and i would create it on an SQL based...
12
18678
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U LEFT JOIN UserTeamAssoc UTA ON UTA.userID = U.userID, Role R, UserRoleAssoc URA, Team T WHERE U.userID = URA.userID AND URA.roleID = R.roleID AND U.userId > 1
52
6359
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
12
13192
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
0
9687
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10251
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.