473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Display joined table records in one parent record

dlite922
1,584 Expert 1GB
Hey guys, I think this is very easy to do and I'm just having a brain fart.

I have a movie database that links to an actors database. 1 move = many actors of course but I want to display the actor information along with the movie like so

series_id, name, actors
123 | John Foo, Jay Bar, James Baz

the two tables are linked by actor_id

Here's what I got:

Expand|Select|Wrap|Line Numbers
  1.  
  2. mysql> SELECT si.series_id, (SELECT a.full_name FROM actor AS a WHERE a.actor_id = sa.actor_id) AS actors
  3.     -> FROM seriesimage AS si LEFT JOIN seriesactor AS sa ON sa.series_id = si.series_id
  4.     -> WHERE si.series_id = 121428;
  5. +-----------+--------------------------+
  6. | series_id | actors                   |
  7. +-----------+--------------------------+
  8. |    121428 | Michael Clarke Duncan    |
  9. |    121428 | NULL                     |
  10. |    121428 | The Rock Douglas Johnson |
  11. +-----------+--------------------------+
  12.  
  13.  
In my mind this is pretty popular and simple to do but I'm not putting the right keywords into Google.

Thanks,



Dan
Nov 10 '09 #1
2 1798
mwasif
802 Expert 512MB
Try the following
Expand|Select|Wrap|Line Numbers
  1. SELECT si.series_id, 
  2. GROUP_CONCAT(SELECT a.full_name FROM actor AS a WHERE a.actor_id = sa.actor_id) AS actors 
  3. FROM seriesimage AS si LEFT JOIN seriesactor AS sa ON sa.series_id = si.series_id 
  4. WHERE si.series_id = 121428
  5. GROUP BY si.series_id;
I suggest you not to mix subquery with JOIN. Use INNER JOIN to get the names of the actors.
Nov 11 '09 #2
dlite922
1,584 Expert 1GB
Sweet! I'll try that next time. I don't remember GROUP_CONCAT. I better look that up.

You guys never disappoint the byte php forum n00bs!



Dan
Nov 12 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: perryche | last post by:
I have 5records, e.g. Rc1, Rc2, Rc3..., when user open up a form, I want it to open to a particular record (say Rc3) then when user chooses the Record Selector , it will go to Rc2 and , it will go...
1
by: Johann Blake | last post by:
I have a dataset that contains a parent table and a child table. A DataRelation exists between the two. I was under the impression from reading the VS docs that when I filled the parent table, the...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
2
by: Bob | last post by:
I got three related datagrid views one parent and two children of the same. The two child tables contain many thousands of records and some of the contents are bitmap files in a sql server...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
4
by: Frank List | last post by:
Hi, I've run into this problem many times and have not found a good solution yet. Here's what I have: table ParentTable - the "1" table table ChildTable- the "many" table ParentTable...
21
by: Killer42 | last post by:
Hi all. I’m almost embarrassed to ask this one, but in fact most of my dabbling in Access has been at a fairly simple level, via the GUI. Now I need to do something slightly deeper, and don’t know...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
4
by: rn5a | last post by:
A MS-Access DB has 3 tables - Teacher, Class & TeacherClass. The Teacher table has 2 columns - TeacherID & TeacherName (TeacherID being the primary key). The Class table too has 2 columns - ClassID...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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...
0
Oralloy
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,...
0
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...

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.