0

I have a database as follows.

security_id   ticker   company_name
----------------------------------------------
   100019     PANL     UNIVERSAL DISPLAY CORP
    10001     NAFC     NASH FINCH CO
   100030     PRVT     PRIVATE MEDIA GROUP INC
   100033     REFR     RESEARCH FRONTIER INC

I have a list of ticker symbols like [GOOG, NAFC, AAPL, PRVT] and I want to get a list of security_id's that are associated with these ticker symbols I have in the list.

I'm new to SQL, so at first I thought of obtaining it one by one by iteration, this works but its really, so I was wondering if there is a SQL statement that can help me.

1
  • What database are you running this query against? Commented Apr 30, 2013 at 14:03

1 Answer 1

2

For SQL Server it would be something similar to this:

select security_id,ticker from <your table name>
where ticker in ('GOOG', 'NAFC', 'AAPL', 'PRVT')

The in takes a list of strings as parameters to compare against the ticker column. This would just be used if you were executing the t-sql in SQL Server Management Studio. If you were to break this out in to a stored procedure then you would have to pass the tickers as CSV and then create a function to split the csv in to a temp table to compare against.

Updated to include the ticker in return to know which security_id belongs to which ticker.

Sign up to request clarification or add additional context in comments.

2 Comments

This is also valid for Sql lite.. IN opeartor supported in it.
I believe it's also valid for PL/SQL (Oracle).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.