473,399 Members | 2,278 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,399 software developers and data experts.

Extract multiple values from single field and join

I'm not extremely well versed in MySQL... this may end up being a fundamental or basic in database design and implementation. (by the way I'm using PHP)

I'll give the trimmed down example of what I'm working with:

Expand|Select|Wrap|Line Numbers
  1. Story Table
  2. id     title     authors     datewritten
  3.  
Expand|Select|Wrap|Line Numbers
  1. Authors Table
  2. id     username     password     name
  3.  
The problem is that each story has multiple authors and each author has written multiple stories.

So I don't know if I need to rethink my database structure or understand something different about how the tables can work together, but my IDEA of how I want to display it / make it work would be:

An HTML Table that displays the list of stories would look like:
Expand|Select|Wrap|Line Numbers
  1. Date            Title                      Authors
  2. 12 Dec 2007     Adventures of an Alien     Mike Smith, Tom Johnson
  3. 24 Jan 2008     Where Pride Went           Tom Johnson, Dan Walters
  4.  
But in the database the AUTHORS field is "2,6" to reference authors of id "2" and "6" then select their name and display it in this case.

I've been reading about INNER JOIN and JOINS in general, but I guess I just can't get my head around it yet.
Feb 6 '08 #1
2 2012
debasisdas
8,127 Expert 4TB
Since you are selecting all the data from a single table why use join at all.

If both the tables have relation try to use this.

Expand|Select|Wrap|Line Numbers
  1. select datewritten,title,authors from story,author where story.authors=author.id
Feb 7 '08 #2
mwasif
802 Expert 512MB
Hi thomasrye,

Welcome to TSDN!!!

You can manage your database at least in 2 ways
  1. The way you are doing right now :-). And display the results in a loop and execute another query to fetch author names within that loop.
  2. Create a third table (intermediate table) that will link authors and story table. The fields will be
    authorid, storyid
    And you don't need to keep authors field in story table. In this approach you can easily and effectively search which author has written how many books.

Let use know if you need more help.
Feb 7 '08 #3

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

Similar topics

11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
0
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
7
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
6
by: Kun | last post by:
I am trying to make an if-statement that will not do anything and print 'nothing entered' if there is nothing entered in a form. I have the following code that does that, however, now even if I...
6
by: ApexData | last post by:
I have 2 tables: Table1 and Table2. Neither one has a primary key because each table will only have 1-record. My form is a SingleForm unbound with tabs (my desire here). Using this form, in...
52
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...
2
by: beargrease | last post by:
I'm kind of comfortable with basic joins, but a current project requires a complex query of many tables. The GROUP_CONCAT(DISTINCT ...) function has been very useful as returning my values as comma...
1
by: bhavinnaik | last post by:
Hi I am new to the IT enviro...although i've used QSL query for a while now but on simple or single queries. Here is the problem... I've got two queries looking at a set of tables to extract the...
3
by: klbachrodt | last post by:
Hi all - I've been browsing this forum for a while now, looking for help, and finally decided to join and ask my question, since I'm not terribly good at writing SQL queries in Access. Here is my...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...

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.