Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I am learning SQLite and I am just a beginner. I have two tables in my database and I am coding some simple queries. If I run the
SQL
.schema
command then it is shown for datatypes and columns in my database:
CREATE TABLE songs (
    id INTEGER,
    name TEXT,
    artist_id INTEGER,
    danceability REAL,
    energy REAL,
    key INTEGER,
    loudness REAL,
    speechiness REAL,
    valence REAL,
    tempo REAL,
    duration_ms INTEGER
);
CREATE TABLE artists (
    id INTEGER,
    name TEXT
);


I have one table for songs and one table for artists. Every song is for one artist. Now I want to get the name of a song in which the artist's name is ZZZZZ, but I do not know how to do it.

What I have tried:

I have tried this query:
SELECT name FROM songs , SELECT name FROM artists WHERE name = "Post Malone";

But it raises an error that :
Error: near "SELECT": syntax error

And actually, I could not solve it. I will be really grateful for your help and advice even if you share a useful link would be great.
Posted
Updated 10-Sep-21 8:39am
Comments
PIEBALDconsult 10-Sep-21 14:04pm    
You want an INNER JOIN.

1 solution

I suggest you go through some basic tutorials because that will be much faster to learn.
Example:
SQL
SELECT s.name AS song_name, a.name AS artist_name 
FROM songs s -- the s here means I can now refer to this table using s instead of typing out the whole word.  Shortcut
INNER JOIN artists a ON s.artist_id = a.id  -- give me the row in artists table where the song's artist id matches the id in the artists table
WHERE a.name = 'ZZZZZ'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900