Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this operand (*= star-equals) in SQL server 2000?

Tags:

I have a query that I pulled from ms sql 2000 and plugged into a MySql query. It did not work, MySql would choke on the *= operator. In this example I have two varchar columns called person_name.

SELECT * FROM tbl1 a, tbl2 b  WHERE a.id = b.id AND a.person_name *= b.person_name 

I know in other languages myInt *= myTotal could also be read as myInt * myInt = myTotal. However, I'm working with varchars that contain all chars, no integers. I wrote it out like:

AND a.person_name * a.person_name = b.person_name 

Voila! It appears to have worked. Can somebody explain what is happening? Is the *= operator converting the chars to their integer equivalents or? And why couldn't I find this operator anywhere on the web?

like image 871
Blaise Swanwick Avatar asked Jun 07 '11 18:06

Blaise Swanwick


People also ask

What is * represent in SQL?

A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

What does *= mean in SQL?

That is the ANSI SQL 1989 syntax for RIGHT OUTER JOIN, where *= would be the LEFT OUTER JOIN.

What is Star called in SQL?

SQL Used. SELECT * FROM <table name>; The asterisk or star symbol ( * ) means all columns. The semi-colon ( ; ) terminates the statement like a period in sentence or question mark in a question.

How do you write greater than and equal to in SQL query?

In SQL, you can use the >= operator to test for an expression greater than or equal to. Let's use the same customers table as the previous example. In this example, the SELECT statement would return all rows from the customers table where the customer_id is greater than or equal to 6000.


2 Answers

In SQL 2000 this was used as a LEFT OUTER JOIN

=* is a RIGHT OUTER JOIN

Your query could be:

SELECT    *  FROM    tbl1 a LEFT OUTER JOIN tbl2 b ON a.person_name = b.person_name WHERE    a.id = b.id 

As stated here:

Specifies an outer join using the nonstandard product-specific syntax and the WHERE clause. The *= operator is used to specify a left outer join and the =* operator is used to specify a right outer join.

like image 176
CristiC Avatar answered Jan 28 '23 11:01

CristiC


In MSSQL, the *= convention in the WHERE clause indicates a join. So what you are really seeing is a LEFT OUTER JOIN between tbl1 and tbl2 on person_name where all the values from tbl1 and the matching values on tbl2 will be returned.

like image 23
bsexton Avatar answered Jan 28 '23 12:01

bsexton