简体   繁体   中英

SQLite Query - Need to get multiple values from multiple keys

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM