I have the following tables and fields.
Actors
-ActorID
-LastName
-FirstName
Movies
-MovieID
-MovieName
-Year
.
.
.
Genres
-GenreID
-Genre
Ratings
-RatingID
-Rating
MoviesActors
-MovieActorID
-MovieID
-ActorID
I figured out how to do the joins to make it display the movie with all its actors. How would I go about making it show one field with the actors first and last name without changing the table though?
Thanks!!
4 1647
You should be able to concatenate the fields with something like: -
SELECT FirstName + ' ' + LastName
-
Oh geesh that was easy.
Thank you very much for your assistance.
Another thing I'm trying to accomplish is this...
I've been trying to figure out how to use the DISTINCT function. Say I'm searching for all movies I have with Will Smith. If I have 3 of the main actors listed under each movie it lists them each 3 times. Here's the query I'm using to list the movies. - SELECT TOP (100) PERCENT dbo.Movies.MovieName AS [Movie Name], dbo.Movies.Year, dbo.Movies.RunningTime AS [Running Time],
-
dbo.Actors.LastName + ', ' + dbo.Actors.FirstName AS [Actor Name], dbo.Genres.Genre, dbo.Ratings.Rating, dbo.Movies.Description
-
FROM dbo.Ratings INNER JOIN
-
dbo.Movies INNER JOIN
-
dbo.Genres ON dbo.Movies.GenreID = dbo.Genres.GenreID ON dbo.Ratings.RatingID = dbo.Movies.RatingID INNER JOIN
-
dbo.MoviesActors INNER JOIN
-
dbo.Actors ON dbo.MoviesActors.ActorID = dbo.Actors.ActorID ON dbo.Movies.MovieID = dbo.MoviesActors.MovieID
-
ORDER BY 'Movie Name', [Actor Name]
Trying to use DISTINCT for the Movies table, but can't get it figured out err.
I think you would be better using a WHERE clause rather than DISTINCT to list all films that have a particular actor as: -
Bad Boys, Smith, Will
-
Bad Boys, Lawrence, Martin
-
Bad Boys, Leoni, Tea
-
are 3 DISTINCT entries so will still show up.
Try something like: -
SELECT m.MovieName
-
,m.Year
-
,m.RunningTime
-
,g.Genre
-
,r.Rating
-
,m.Description
-
FROM dbo.Movies m
-
JOIN dbo.Genres g ON g.GenreID = m.GenreID
-
JOIN dbo.Ratings r ON r.RatingID = m.RatingID
-
JOIN dbo.MoviesActors ma ON ma.MovieID = m.MovieID
-
JOIN dbo.Actors a ON a.ActorID = ma.ActorID
-
WHERE a.LastName = 'Smith'
-
AND a.FirstName = 'Will'
-
If you knew the ActorID rather than text, searching you query would be quicker (but I don't know how you are using your database).
I have also used table aliases in the above code as IMHO it makes the query not only quicker to write but easier to read!
Hope this helps
Actually I am going to use the ActorID as the search instead of the name. Just wanted to see where I was going wrong on the DISTINCT thing. Using WHERE does sound a lot more sensible though. Thanks for the direction. Also thanks for the info on the aliases. That does indeed looks like it'll make things look cleaner.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Doug Farrell |
last post by:
Hi all,
I'm trying to do the following from within a code module:
import re
# text to match
text = "Good morning x something /x, how are you today x something
else /x"
|
by: JMCN |
last post by:
object invalid or no longer set - confusion of the recordset in access
2003.
i am currently converting from access 97 to access 2003. majority of
the codes converted over perfectly fine, though...
|
by: i_have_control |
last post by:
I'd be grateful for any input on this one:
I have three web domains. The destinations of two are set to folders
on the first, though that fact is transparent to the user (i.e: it does
not...
|
by: Steve |
last post by:
I have a form with a dataset and a datagrid.
I created a dataview on this dataset.
When the user modifies the datagrid, I look up this record in the dataview
to make sure it is unique.
Here is...
|
by: joelagnel |
last post by:
hi friends,
i've been having this confusion for about a year, i want to know the
exact difference between text and binary files.
using the fwrite function in c, i wrote 2 bytes of integers in...
|
by: Richard Lewis Haggard |
last post by:
I'm having a problem with what appears to be some sort of confusion with
references. I have a single solution with a dozen projects which has been
working quite nicely for a while. The references...
|
by: Riaaaa |
last post by:
Hello,
We are doing the project in VB.Net.
We had a great confusion for ASP.Net and VB.Net.
Is VB.Net project performed in Microsoft Visual Studio 2005 ??
We have...
|
by: mumbai10 |
last post by:
oracle quary
I want to transfer data from ms excel to oracle or how can i import data from ms excel to oracle
|
by: dreamer247 |
last post by:
hii..
I have written a quary in sqlserver 2000 and the out put is not as expected...
the quary is..
$sql="SELECT NAME,ROOM,DESIG,EMAIL,PHONE,START_DATE,END_DATE,CHAIRED_BY FROM CRB_MEETING...
|
by: ahmed222too |
last post by:
when i use this quary to add new column, the engine reject the table name and focus on (-) in the table name
alter table AH10-A1*1*1-101006 add column sss
note: this schema of table name...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |