Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

How to select where in sql?

Asked by Celina Lagunas Sep 29, 2022 1.1K views 1 answer
Share

About this question

I have made a draft remote application on top of libpq for PostgreSQL. It behaves well, but I have profiled the general functioning of the application. For each final business result that I produce, it happens that I call something like 40 select clauses (over tcpip).

I have reminiscences from SQL-Server reminding me to minimize the number of interactions between my remote application and the database. Having analyzed my selects, I do think I could reduce this number to 3 SELECT clauses, using joins. But I don't remember the syntax for using the result of a SELECT in another SELECT.

E.g.:

SELECT * FROM individual

INNER JOIN publisher

ON individual.individual_id = publisher.individual_id

WHERE individual.individual_id = 'here I would like to use the results of a another select'

This other SELECT would be simply of the kind:

SELECT identifier FROM another_table WHERE something='something'

Here is the simplified tables layout, declined a number of times for different item_types ... (3 totally different types, hence the 3 SQL queries if optimised).

table passage

  id_passage PK
  business_field_passage bytea
table item
  id_item PK
  id_passage FK
  business_field_item text
table item_detail
  id_item_detail PK
  id_item FK
  business_field_item_detail text
  image_content bytea

There are several id_item for one id_passage.

There are several id_item_detail for one id_item.

How would you write that?

What is the name for describing the action of redirecting one select into another (if any)?


Your answer

1 Answer

More SQL Server discussions