I'm working on a query like this:
SELECT * FROM requests where (id,langid) IN (SELECT nid,langid FROM node)
My questions are
I know is not the best solution and a JOIN would work but I'm not interested in that.
Now, we have to select the column First_Name from the given table. When we have to select multiple columns along with some condition, we put a WHERE clause and write our condition inside that clause.
But yes, you can use two WHERE.
All you need to do is use the multiplication operator (*) between the two multiplicand columns ( price * quantity ) in a simple SELECT query. You can give this result an alias with the AS keyword; in our example, we gave the multiplication column an alias of total_price .
The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition.
Standard and portable SQL would be EXISTS.. and is semantically the same IN
SELECT *
FROM requests R
WHERE
EXISTS (SELECT *
FROM node n
WHERE r.id = n.nid AND r.langid = n.langid
)
The multi-column IN isn't portable to SQL Server or Sybase at least.
Other notes:
I checked that with PostgreSQL and it works (it is officially supported), but it's your responsibility to make id ↔ nid and langid ↔ langid column types compatible (or use explicit casting).
I think it is pretty standard construct. I have SQL:2003 draft and there is in predicate defined (as well as mentioned exists predicate).
8.4 <in predicate>
Function
Specify a quantified comparison.
Format
<in predicate> ::= <row value predicand> <in predicate part 2>
<in predicate part 2> ::= [ NOT ] IN <in predicate value>
<in predicate value> ::=
<table subquery>
| ... (rest is not important here)
EDIT:
As checked works well under MySQL too (version 5.0.90-log). Here is documentation link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With