0

this is a question about search() in pset8 Mashup.

How does one select rows given multiple characteristics(for example in pseudo code, SELECT * THAT CONTAIN KEYWORDS "New Haven" AND "Connecticut" AND "06404" AND "US" within ANY of the fields of PLACES database)

Right now, my code parses any search query (no matter how long) that sanitizes any non-alphabetic and non-number characters. I would have (in the case of my example) ["New Haven", "Connecticut", "06404", "US"].

How can I use my array (or any way) to select rows from my database that satisfy all the conditions above without knowing which characteristics goes with which keyword in the array?

0

If you read the problem specs, there's an SQL statement there that searches similar terms in the specified fields in the table with the provided query -- LIKE. You can use that together with decision operators like AND or OR and you'd eventually form a database query that somehow looks like this:

SELECT * FROM PLACES WHERE [:postal_code] LIKE [:query] OR [:city] LIKE [:query] OR [:state] LIKE [:query]

Just replace the variables in brackets with the ones you use! Good luck and happy coding :)

2
  • 1.) what is the purpose of the brackets? 2.) if I have a query that contains a postal code , city , and state inside of it (ie query = "6830 Naperville IL") will SQL still pick up on this and return me information that contains all three characteristics (a user could order state, city, and postal code in different ways which I think your code does not take into account for). Aug 2 '18 at 15:15
  • They are just for visual purposes, they mark the variables with which you'll have to replace with the ones you've wrote, you're free to remove them. And yes, SQL will still pick up what you're trying to search even in whatever sequence you put it in. Aug 3 '18 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .