Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7023959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:46:39+00:00 2026-05-27T23:46:39+00:00

i have a database where i cannot figure out how to fetch the book

  • 0

i have a database where i cannot figure out how to fetch the book data. i’ll be explaining how i did it before and how i plan to do it now.

to make it simple, i’ll take the “books” example since it’s the easiest to show the relationship. before, i had this structure which i found heavy on the DB:

Books:
book_id
title 
author_name
genre_name

it was easy to query individual books, all books, books by author and books by genre. the problem here was when i need to get the list of authors or genres. i had to select ALL books, detect possible duplicates, identicals, uniques etc. before handing them over to the browser. i already felt the lag in processing.

so what i plan to do now is this: i have 3 tables, one for books, another for authors and another for genres.

Books:       Authors:      Genre: 
book_id      author_id     genre_id
title        author_name   genre_name
author_id
genre_id

this way, i can tag the books by author_id and genre_id as well as easily get all authors and genres more quickly without affecting the “get by author” and “get by genre”. Also, i can easily change the book author and/or genre by altering author_id and genre_id.

but if i select a book, how do i do it when the normal select * from Books where book_id=something returns only the ids of genres and authors? how do i do it to return author names and genre names? subquery? a separate query? or is there actually a one-liner query that i don’t know about?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:46:39+00:00Added an answer on May 27, 2026 at 11:46 pm

    You need to use a INNER JOIN so you could do something like this

    SELECT b.book_id, b.title, a.author_name, g.genre_name FROM Books 
    INNER JOIN Authors a ON b.author_id=a.author_id 
    INNER JOIN Genre g ON b.genre_id=g.genre_id
    WHERE book_id=12
    

    As an alternative if you did not want to create separate tables (which is good design by the way) you could use a DISTINCT query

     SELECT DISTINCT author_name FROM Books;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple error that I just cannot figure out why I am
This might be really simple, but i cannot figure out the problem with this
After several hours of tinkering I cannot seem to figure this out. I have
I have another strange bug which I cannot figure out. I try to create
I cannot figure out how to make a parent, child (by an id) that
I have been staring at this code for hours now and I cannot figure
I have a database issue that i currently cannot wrap my head around with
I have a client that has a PostgreSQL database and he cannot remember the
I have a legacy database set with NLS_LANG set to IW8ISO8859P8. This I cannot
I have another question. XMLhttpRequests haunt me. Everything is now in the database but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.