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 8208373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:19:14+00:00 2026-06-07T09:19:14+00:00

I have 3 tables in SQLite database: Songs: _id | name | length |

  • 0

I have 3 tables in SQLite database:

Songs:

_id | name | length | artist_id (foreign key) | album_id (foreign key)

Artists:

_id | name

Albums:

_id | name

I need a query (use it in an Android app) of a table that consists of the following columns:

_id | name | length | artist_id | artist_name | album_id | album_name

However, I write the following query statement:

SELECT Songs._id, Songs.name, Songs.length, Songs.artist_id, Artists.name, Songs.album_id, Albums.name FROM Songs, Artists, Albums WHERE Songs.artist_id = Artists._id AND Songs.album_id = Albums._id

but it gives me an empty table. I tried OR instead of AND and it gives incorrect results (every song duplicates in each album, though the artist is correct). How can I fix my query statement to join the 3 tables in a single table?

  • 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-06-07T09:19:16+00:00Added an answer on June 7, 2026 at 9:19 am

    Using an explicit JOIN instead of an implicit one, the following should get what you want, although it is curious that your implicit join syntax did not return correct results in the first place. I have used a LEFT JOIN, to account for songs which do not have an associated artist or album, but that may not be necessary for your data set and an INNER JOIN could be used instead.

    I have also added column aliases to eliminate ambiguity when fetching rows, since you have similar column names in most of your tables (id, name).

    SELECT
      Songs._id AS song_id,
      Songs.name AS song_name, 
      Songs.length, 
      Songs.artist_id AS artist_id, 
      Artists.name AS artist_name, 
      Songs.album_id AS album_id, 
      Albums.name AS album_name
    FROM 
     Songs 
     LEFT JOIN Artists ON Songs.artist_id = Artists._id
     LEFT JOIN Albums ON Songs.album_id = Albums._id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my dev database (SQLite) i have some tables (like vocabularies) which i need
In this example we have 3 related tables on a SQLite database: CREATE TABLE
I have an SQLite database. I created the tables and filled them with a
So this is what I have, I have a SQLite database with 3 tables:
I have a table in a SQLite database with multiple key fields (lang and
I have two tables, Proteins and Species . Protein has Species.Id as foreign key
I have a SQLite database, and several tables within that datbase. I am developing
I have a SQLIte database with tables for places and tables for tags, CREATE
I need to get column names and their tables in a SQLite database. What
I have an SQLite database with 4 tables in it that I want to

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.