Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:30:49+00:00 2026-06-13T23:30:49+00:00

I have the following 2 SQL syntax that I’m looking to combine into 1

  • 0

I have the following 2 SQL syntax that I’m looking to combine into 1 SQL syntax

SELECT sentFrom 
FROM tableName 
WHERE id = :varid 
AND sentFrom != :vartext

SELECT sentTo 
FROM tableName 
WHERE id = :varid 
AND sentTo != :vartext

I guess I should give an example:

MYSQL TABLE

-----------------------------------
sentFrom          sentTo
1                 2
1                 3
2                 1
2                 3

query

select sentFrom where sentFrom != 1 and select sentTo where sentTo != 1

Returns:

sentTo 2 but not sentFrom 1

sentTo 3 but not sentFrom 1

sentFrom 2 but not sentTo 1

sentFrom 2 and sentTo 3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:30:50+00:00Added an answer on June 13, 2026 at 11:30 pm

    I think this should help.

    SELECT a.sentFrom , b.sentTo FROM 
     (SELECT id, sentFrom FROM tableName WHERE id = :varid AND sentFrom != :vartext) a
    JOIN 
     (SELECT id, sentTo FROM tableName WHERE id = :varid AND sentTo != :vartext) b
    ON a.id = b.id;
    

    If you think, ID is not common in the rows selected in each query then remove the join condition ON a.id = b.id. In that case it will return you the Cartesian product of records of query one to query 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MS SQL function that is called with the following syntax: SELECT
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
I have the following SQL Server query: SELECT area FROM places WHERE REPLACE(area,'-',' ')
I have the following SQL query: IF EXISTS(SELECT * FROM component_psar WHERE tbl_id =
I have the following SQL statement SELECT be.*, it.order_number FROM songs AS be INNER
Hi I have following sql statement that gives me the the first_name and total
I have the following SQL snippet within a select statement: CASE WHEN wot.id LIKE
I have the following SQL query: SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG
I have the following SQL statement which has a very bad performance: SELECT frmInstLastModifiedDate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.