November 27, 2017 at 3:43 pm
Hello,
I have an SQL database of of songs with a table that consists of 8 columns of information on words of a song. each row represents a single word from the songs lyrics:
1. `songSerial` - the serial number of the song
2. `songName` - the song name
3. `word` - a single word from the song's lyrics
4. `row_number` - the number of the row that the word is found
5. `word_position_in_row` - the number of the word in the row alone
6. `house_number` - the number of the house the word belongs to
7. `house_row` - the number of the row in the house that the word is found in
8. `word_number` - the number of the word out of all the songs lyrics
example: { 4 , The Scientist , secrets , 8 , 4 , 2 , 1 , 37 }
Now I want to query all the songs that contains a group of words. For instance all the words that have the sentence: "I Love You" in them. It must be in that order and not from different rows or houses.
Can anyone help ?
Thank you
November 27, 2017 at 5:27 pm
Please post create table statement and inserts with sample data.
November 27, 2017 at 5:52 pm
Davismarsel - Monday, November 27, 2017 3:43 PMHello,
I have an SQL database of of songs with a table that consists of 8 columns of information on words of a song. each row represents a single word from the songs lyrics:
1. `songSerial` - the serial number of the song
2. `songName` - the song name
3. `word` - a single word from the song's lyrics
4. `row_number` - the number of the row that the word is found
5. `word_position_in_row` - the number of the word in the row alone
6. `house_number` - the number of the house the word belongs to
7. `house_row` - the number of the row in the house that the word is found in
8. `word_number` - the number of the word out of all the songs lyrics
example: { 4 , The Scientist , secrets , 8 , 4 , 2 , 1 , 37 }
Now I want to query all the songs that contains a group of words. For instance all the words that have the sentence: "I Love You" in them. It must be in that order and not from different rows or houses.
Can anyone help ?
Thank you
I did this once for an automotive parts system and it turned out to be incredibly fast (sub-second on a huge table). The table was a bit more normalized but, if you don't mind an additional index, I believe we can still keep the speed up. I need some more information though...
1. Is there a maximum number of words to search for?
2. Can you post the CREATE TABLE statement for this table including ALL indexes?
3. Are you allowed to used dynamic SQL provided that I also show you how to avoid things like SQL Injection in the process?
4. Can you attach a Tab Delimited and compressed zip file of a couple of thousand rows from that table so that I can have something to test with? Of course, it would also be convenient if the fields of data in the file matched the left to right order of the fields listed top to bottom in the CREATE TABLE statement. It would also be good if you made sure there were enough data for at least 2 complete songs but more, if possible, to ensure that I've remembered the code correctly.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2017 at 11:26 am
Hi,
Thanks.
There isn't a maximum number of words.. it's dynamic.
I'm allowed to use everything
I have attached 2 scripts in text files: 1 for creating the database and table , and the second for inserting some data of 3 songs.
Hope you manage it Thank you
David
November 28, 2017 at 12:19 pm
This seems like homework and MySQL.
Is any of those assumptions correct?
November 28, 2017 at 2:06 pm
It's actually an experiment of an app I am creating in java for managing songs and lyrics. Nothing to do with homework or exercises.
And yes I am working with MySQL workbench 6.0
November 28, 2017 at 3:17 pm
Davismarsel - Tuesday, November 28, 2017 2:06 PMIt's actually an experiment of an app I am creating in java for managing songs and lyrics. Nothing to do with homework or exercises.
And yes I am working with MySQL workbench 6.0
You do realize that there are some pretty serious differences between SQL Server (and this is a Microsoft SQL Server site) and MySQL, correct? I don't even know if MySQL can use CTEs (Common Table Expressions), never mind the cascading CTEs that I was going to demonstrate.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 29, 2017 at 6:13 am
Jeff Moden - Tuesday, November 28, 2017 3:17 PMDavismarsel - Tuesday, November 28, 2017 2:06 PMIt's actually an experiment of an app I am creating in java for managing songs and lyrics. Nothing to do with homework or exercises.
And yes I am working with MySQL workbench 6.0You do realize that there are some pretty serious differences between SQL Server (and this is a Microsoft SQL Server site) and MySQL, correct? I don't even know if MySQL can use CTEs (Common Table Expressions), never mind the cascading CTEs that I was going to demonstrate.
Apparently, Release 8.0 of MySQL introduced CTEs to the product a little over a year ago.
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/
https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html
https://dev.mysql.com/doc/refman/8.0/en/with.html
Be a bit careful with the examples on that last link... they have some serious RBAR going on in some of those.
Since CTEs are available in MySQL, I'll try to write the SQL Server example I'm thinking of for this using the data that was provided in the next day or two.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 25, 2022 at 9:44 am
This was removed by the editor as SPAM
July 26, 2022 at 2:59 am
This was removed by the editor as SPAM
August 16, 2023 at 8:21 am
This was removed by the editor as SPAM
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy