1

I want to build a simple project with the following tables:

 CREATE TABLE artist(
 artistid    INTEGER PRIMARY KEY, 
 artistname  TEXT
 );
 CREATE TABLE track(
 trackid     INTEGER,
 trackname   TEXT, 
 trackartist INTEGER,
 FOREIGN KEY(trackartist) REFERENCES artist(artistid)
 );

I want my app to be user-friendly so how may I display the artistname instead of the artistid in the spinner of My Track Form? What SQLite statement should I use? After displaying all the artist names, what SQLite statement should I use to insert properly in my database?

Track Form Example:

Track Name: [EditText]

Artist: [Spinners]

TJ Riceball
  • 240
  • 1
  • 2
  • 11
  • Don't you want to display *all* artist names in the spinner's list? – CL. May 15 '14 at 08:53
  • Yes, I want to display all of them. – TJ Riceball May 15 '14 at 08:56
  • @Simulant You'd still need the ID. – CL. May 15 '14 at 08:59
  • Hello guys, I updated my question. I want to hear your ideas on how to implement the insert statement after displaying the artist names. – TJ Riceball May 15 '14 at 09:18
  • That INSERT statement is simple. What specific problem do you have with it? – CL. May 15 '14 at 09:22
  • For example, the value displayed of the spinner is "Linkin Park" so this is obviously a string by the trackartist column datatype is integer. How do I retrieve the artistid? – TJ Riceball May 15 '14 at 09:28
  • Your problem is not with the SQL; it is about how to manage the data inside your app. (Look at [Joaquin Alberto's answer](http://stackoverflow.com/a/8116756/11654).) – CL. May 15 '14 at 09:46

1 Answers1

1

The following Statement returns a List of Artist names and their track-names.

SELECT a.artistname, t.trackname
FROM artistname a, track t
WHERE a.artistid = t.trackartist;
Simulant
  • 19,190
  • 8
  • 63
  • 98