简体   繁体   中英

SQL Transact-Sql Error

I'm trying to get information from multiple tables and tried to do so with an inner join, although it appears that my syntax is correct, I get an error about Transact- Sql statements. I read documentation on case statements, but need clarification as to what I'm doing wrong. Any help is appreciated. Thank you in advance.

Query:

SELECT 
    person.Id, person.firstName, person.lastName, person.birthdate, 
    Gender.Gender, household.Id, family.Id
FROM 
    (((person
INNER JOIN 
    family ON persons.Id = family.Id)
INNER JOIN 
    household ON persons.Id = household.Id)
INNER JOIN 
    Gender ON persons.id = Gender.Id);

Error:

Only SELECT Transact-Sql statements can be used.

you have to remove all parentheses for this case:

SELECT 
person.Id, person.firstName, person.lastName, person.birthdate, 
Gender.Gender, household.Id, family.Id
FROM  person
INNER JOIN family ON persons.Id = family.Id
INNER JOIN household ON persons.Id = household.Id
INNER JOIN Gender ON persons.id = Gender.Id;

The query you have in its current state is trying to select from a derived table.

Simply remove the parenthesis to set up your proper joins.

    SELECT 
    person.Id, person.firstName, person.lastName, person.birthdate, 
    Gender.Gender, household.Id, family.Id
    FROM  person
    INNER JOIN family ON person.Id = family.Id
    INNER JOIN household ON person.Id = household.Id
    INNER JOIN Gender ON person.id = Gender.Id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM