How to compare two columns in two different tables in SQL? [closed] - sql-server-2008

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two tables. Table A and Table B. How can I compare a column in A (data type: date)
with a column in B (data type: date) with condition: column in B >= column in A?

There are two things being asked here.
1) Show me those that are greater
2) Tell me the comparison
So, to do both, try this. Part (1) is in the where clause, and part (2) is in the select statement.
select *, datediff(day, b.col, a.col) as ColumnDifference
from TableA a, TableB b
where b.col >= a.col
Documentation for datediff: http://msdn.microsoft.com/en-us/library/ms189794(v=sql.100).aspx

Related

Updating a column with a Count of data from another column in the same table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear

What is the difference in MySQL between JOIN ON and WHERE? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What is the difference in MySQL between:
SELECT * FROM A JOIN B ON A.item=B.item
and
SELECT * FROM A, B WHERE A.item=B.item
Multi FROM is similar to JOIN operation, you have to use WHERE clause to limit the rows returned. And it correspond to an implicit join.
But as you can read in comments, you should use explicit JOIN (OUTER JOIN, INNER JOIN, LEFT JOIN, RIGHT JOIN) that determine how the data is "linked" in ON clause.

how to convert colums to rows in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a table with the following values
and I need the output values as below.
Please help to arrive the code
It's not pretty, but this would work:
select *
from
(
select nams_contract_number, 1 as Sequence, 'Preqc' as DataType, act_preqc, est_preqc
from table
union all
select nams_contract_number, 2 as Sequence, 'abstractoin' as DataType, act_abstraction, est_abstraction
from table
union all
select nams_contract_number, 3 as Sequence, 'review' as DataType, act_review, est_review
from table
union all
select nams_contract_number, 4 as Sequence, 'postreview' as DataType, act_postreview, est_postreview
from table
) x
order by x.nams_contract_number, x.sequence

in Table A has 10 rows and table B has 10 rows. The product of Table A and Table B would have 100 rows. ? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In mySQL Table A has 10 rows and table B has 10 rows. The product of Table A and Table B would have 100 rows?
I am stuck.
If table1 has N rows and table2 has M rows, and you do:
SELECT * FROM table1 A, table2 B
you get N X M rows.
Check if you like Generating a Cartesian Product.
What exactly is the product of two tables? If you join them loosely and select one column from each theb yes. But it makes no sense to do it.
You are probably not joining them properly. If you could post your code it would help.

Union query in mysql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have 2 tables catelog and catelog copy. And, I need to to display both these table fields as one table using mysql.
Can anyone correct this code for joining 2 tables?
$result = mysql_query("SELECT * FROM catelog WHERE title='".$fileid."'union
select status from catelog_copy " );
SELECT statements you'd like to UNION have to return the same number of columns and types of those columns should match.
So
SELECT a, b, c FROM table1 UNION SELECT a, b, c FROM table2
will work, but
SELECT a, b FROM table1 UNION SELECT a, b, c FROM table2
will not.
Names of the fields and the fields themselves might be different though.